[LLVMdev] Enabling vectorization with LLVM 3.3 for a DSL emitting LLVM IR

Stéphane Letz
2013-07-05T14:50:16Z

Le 5 juil. 2013 à 04:11, Tobias Grosser <tobias at grosser.es> a écrit :

> On 07/04/2013 01:39 PM, Stéphane Letz wrote:
>> Hi,
>>
>> Our DSL can generate C or directly generate LLVM IR. With LLVM 3.3, we
can vectorize the C produced code using clang with -O3, or clang with -O1 then
opt -O3 -vectorize-loops. But the same program generating LLVM IR version cannot
be vectorized with opt -O3 -vectorize-loops. So our guess is that our generated
LLVM IR lacks some informations that are needed by the vectorization passes to
correctly work.
>>
>> Any idea of what could be lacking?
>
> Without any knowledge about the code guessing is hard. You may miss the
'noalias' keyword or nsw/nuw flags, but there are many possibilities.
>
> If you add '-debug' to opt you may get some hints. Also, if you
have a small test case, posting the LLVM-IR may help.
>
> Cheers,
> Tobias
>


I did some progress:

1) adding a DataLayout in my generated LLVM Module, explicitly as a string. BTW
is there any notion of "default" DataLayout that could be used? How is
a LLVM Module supposed to know which DataLayout to use (in general) ?

2) next the resulting module could not be vectorized with "opt -O3
-vectorize-loops -debug  -S m1.ll -o m2.ll", but if I do in "two
steps" like:

opt -O3 -vectorize-loops -debug S m1.ll -o m2.ll

opt -O3 -vectorize-loops -debug S m2.ll -o m3.ll

then it works….

Any idea?

Thanks.