[llvm-dev] unable to emit vectorized code in LLVM IR

hameeza ahmed via llvm-dev llvm-dev at lists.llvm.org
Thu Aug 17 09:52:10 PDT 2017


I want to vectorize the user given inputs. when opt does vectorization user
supplied inputs (from a text file) will be added using AVX vector
instructions.

as you pointed; When i changed my code to following:

int main(int argc, char** argv) {
int a[1000], b[1000], c[1000];
int aa=atoi(argv[1]), bb=atoi(argv[2]);
for (int i=0; i<1000; i++) {
a[i]=aa, b[i]=bb;
 c[i]=a[i] + b[i];
printf("sum: %d\n", c[i]);

}

I am getting error remark: <unknown>:0:0: loop not vectorized: call
instruction cannot be vectorized.

I am running following commands:
clang  -S -emit-llvm sum-vec.c -march=knl -O3 -mllvm -disable-llvm-optzns
-o sum-vec.ll
opt  -S -O3 -force-vector-width=64 sum-vec.ll -o sum-vec03.ll

How to achieve this? Please help.





On Thu, Aug 17, 2017 at 10:44 AM, Nemanja Ivanovic <nemanja.i.ibm at gmail.com>
wrote:

> I'm not sure what you expect to have vectorized here. If you look at the
> emitted code, there's no loop. It's just an add and a multiply as you might
> expect when adding a loop-invariant sum 1000 times in a loop.
>
> On Wed, Aug 16, 2017 at 11:38 PM, hameeza ahmed via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hello,
>> I have written the following code. when i try to vectorize it through
>> opt. i am not getting vectorized instructions.
>>
>> #include <stdio.h>
>> #include<stdlib.h>
>> int main(int argc, char** argv) {
>> int sum=0; int a=atoi(argv[1]); int b=atoi(argv[2]);
>> for (int i=0;i<1000;i++)
>> {
>> sum+=a+b;
>> }
>>
>> printf("sum: %d\n", sum);
>> return 0;
>> }
>> i use following commands:
>> clang  -S -emit-llvm sum-main.c -march=knl -O3 -mllvm
>> -disable-llvm-optzns -o sum-main.ll
>> opt  -S -O3 -force-vector-width=64 sum-main.ll -o sum-main03.ll
>>
>> why is that so? where am i doing mistake? i am not getting vectorized
>> operations rather getting scalar operations.
>>
>> Please help.
>>
>> Thank You
>>
>> Regards
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170817/0be8296b/attachment.html>


More information about the llvm-dev mailing list