<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Nov 14, 2021, at 14:09, zxl via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">Hi:<div class=""> I want to use clang auto-vectorization for this code:</div><div class="">```</div><div class=""><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">#include <stdio.h></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">#include <stdint.h></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue"; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">void test() {</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>int a[100];</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>for (int64_t i = 0; i < 100; i++) {</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>a[i] = i / 8;</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>}</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>printf("%ld %ld", a[0], a[99]);</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">}</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue"; min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">int main(int argc, char** argv) {</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class=""><span class="Apple-converted-space"> </span>test();</div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 13px; line-height: normal; font-family: "Helvetica Neue";" class="">}</div></div><div class=""><div style="color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Menlo, Monaco, "Courier New", monospace; font-size: 12px; line-height: 18px; white-space: pre;" class=""><div class=""></div></div></div><div class="">```</div><div class="">It worked with this command: clang -S -O3 vector_divide.c and it can get successfully vectorized asm.</div><div class="">But i want to use auto-vectorization as below:</div><div class="">clang -S -emit-llvm -mllvm -force-vector-width=8 vector_divide.c -o vec_dev.ll</div><div class="">opt -loop-vectorize -force-vector-width=8 -S vec_dev.ll -o vec_opt_dev.ll</div><div class="">clang -S vec_opt_dev.ll</div><div class="">Then it can't worked, what should i do?</div></div></blockquote><br class=""></div><div>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. </div><div><br class=""></div><div>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. <a href="https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilderPipelines.cpp" class="">https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilderPipelines.cpp</a>)</div><div><br class=""></div><div>Alternatively you can try extracting the IR before vectorization, by running `clang -O3` and using the `-print-before-*` flags.</div><div><br class=""></div><div>Cheers,</div><div>Florian</div><br class=""></body></html>