Dear all, Greetings. I want to generate the intermediate code (.ll file) after having LLVM auto-vectorization transformation on the source C file. I have the following code (find_max.c) on which I want to apply auto-vectorization. int main() { int i, n, max, arr[50]; for(i = 0; i < 35; i++) { printf("arr[%d] = ", i); scanf("%d", &arr[i]); } max = arr[0]; for(i = 1; i < 35; i++) { if(arr[i] > max) { max = arr[i]; } } } I have tried the following. 1. clang -S -emit-llvm find_max.c -o find_max.ll 2. opt -loop-vectorize -force-vector-width=8 find_max.ll -o find_max_opt.ll and 1. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector 2. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector -o find_max.ll All the above options generate binary files. I request you to please help. Thanks and regards, Sudakshina -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210514/b6884f0a/attachment.html>
Hi, Not sure what you mean by only getting binaries: "clang -S -emit-llvm" should produce a .ll and so will opt.> clang -S -emit-llvm find_max.c -o find_max.llSince no optimisation level is specified, this will result in very unoptimised code, probably resulting in vectorisation not triggering. I usually do "clang -O3 -S -emit-llvm -mllvm -print-before-all", or something equivalent, and then grab the IR just before vectorisation.> clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector>From a very quick look, this will probably not show anything because of your example: the second loop has no effect and is optimised away, only the first remains which is fully unrolled. Returning "max" will probably help.________________________________ From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Sudakshina Dutta via llvm-dev <llvm-dev at lists.llvm.org> Sent: 14 May 2021 04:16 To: LLVM Development List <llvm-dev at lists.llvm.org> Subject: [llvm-dev] Auto-vectorization option Dear all, Greetings. I want to generate the intermediate code (.ll file) after having LLVM auto-vectorization transformation on the source C file. I have the following code (find_max.c) on which I want to apply auto-vectorization. int main() { int i, n, max, arr[50]; for(i = 0; i < 35; i++) { printf("arr[%d] = ", i); scanf("%d", &arr[i]); } max = arr[0]; for(i = 1; i < 35; i++) { if(arr[i] > max) { max = arr[i]; } } } I have tried the following. 1. clang -S -emit-llvm find_max.c -o find_max.ll 2. opt -loop-vectorize -force-vector-width=8 find_max.ll -o find_max_opt.ll and 1. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector 2. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector -o find_max.ll All the above options generate binary files. I request you to please help. Thanks and regards, Sudakshina -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210514/5ceeebdb/attachment.html>
Try opt -S to get text IR instead of bitcode. The second group of commands use clang -c so produce a compiled object file. For text IR you need -S -emit-llvm like in the first group. Nigel From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Sudakshina Dutta via llvm-dev Sent: 14 May 2021 04:17 To: LLVM Development List <llvm-dev at lists.llvm.org> Subject: [llvm-dev] Auto-vectorization option Dear all, Greetings. I want to generate the intermediate code (.ll file) after having LLVM auto-vectorization transformation on the source C file. I have the following code (find_max.c) on which I want to apply auto-vectorization. int main() { int i, n, max, arr[50]; for(i = 0; i < 35; i++) { printf("arr[%d] = ", i); scanf("%d", &arr[i]); } max = arr[0]; for(i = 1; i < 35; i++) { if(arr[i] > max) { max = arr[i]; } } } I have tried the following. 1. clang -S -emit-llvm find_max.c -o find_max.ll 2. opt -loop-vectorize -force-vector-width=8 find_max.ll -o find_max_opt.ll and 1. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector 2. clang -O3 -c find_max.c -Rpass=vector -Rpass-analysis=vector -o find_max.ll All the above options generate binary files. I request you to please help. Thanks and regards, Sudakshina -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210514/1a3fd217/attachment.html>