[llvm-dev] Auto-vectorization command flag not work in clang-13

Florian Hahn via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 14 09:11:37 PST 2021


Hi,

> On Nov 14, 2021, at 14:09, zxl via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Hi:
>    I want to use clang auto-vectorization for this code:
> ```
> #include <stdio.h>
> #include <stdint.h>
> 
> void test() {
>   int a[100];
>   for (int64_t i = 0; i < 100; i++) {
>     a[i] = i / 8;
>   }
>   printf("%ld %ld", a[0], a[99]);
> }
> 
> int main(int argc, char** argv) {
>   test();
> }
> ```
> It worked with this command: clang -S -O3 vector_divide.c  and it can get successfully vectorized asm.
> But i want to use auto-vectorization as below:
> clang -S -emit-llvm -mllvm -force-vector-width=8 vector_divide.c -o vec_dev.ll
> opt -loop-vectorize -force-vector-width=8 -S vec_dev.ll -o vec_opt_dev.ll
> clang -S vec_opt_dev.ll
> Then it can't worked, what should i do?

The IR you generate from Clang is unoptimized. -loop-vectorize requires certain optimization to happen before running the pass, to bring the input IR in a suitable shape. 

If you want to run loop vectorization on a piece of IR emitted from Clang without optimizations, you will have to run a set of required optimizations before that (including mem2reg, instcombine, simplifycfg, loop-rotate). Take a look at the place of loop-vectorize in the optimization pipeline to see what kind of passes may be required (e.g. https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilderPipelines.cpp <https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilderPipelines.cpp>)

Alternatively you can try extracting the IR before vectorization, by running `clang -O3` and using the `-print-before-*` flags.

Cheers,
Florian

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211114/0d47a54b/attachment.html>


More information about the llvm-dev mailing list