[llvm-dev] Pattern not recognized as reduction
Himanshu Shukla via llvm-dev
llvm-dev at lists.llvm.org
Sun Feb 11 23:41:09 PST 2018
Reduction Not Captured By LLVM
CODE_1
------------------------------------------------------------
------------------------------------------------------------
--------------------
#include <stdio.h>
int main()
{
int sum[1000]={1,2,3,4};
for (int i=1;i<1000;i++)
{
sum[0] +=sum[i-1];
}
}
------------------------------------------------------------
------------------------------------------------------------
--------------------
In the code given above, we tried to run the vectorization pass of LLVM.
The remark emitted by vectorizer says the following :-
REMARKS_1
------------------------------------------------------------
-------------------------------------------------------------------
test6.c:8:11: remark: loop not vectorized: value that could not be
identified as reduction is used outside the loop [-Rpass-analysis=loop-
vectorize]
sum[0] += sum[i-1];
^
test6.c:6:3: remark: loop not vectorized: unsafe dependent memory
operations in loop. Use #pragma loop distribute(enable) to allow loop
distribution to attempt to
isolate the offending operations into a separate loop
[-Rpass-analysis=loop-vectorize]
for(int i=100;i<1000;i++)
^
------------------------------------------------------------
-------------------------------------------------------------------
The command used for capturing the remarks from above code is
clang -O3 -ffast-math -mavx2 -Rpass=loop-vectorize
-Rpass-analysis=loop-vectorize file.c
On the other hand , if we replace in the same code sum[0] by x and making
very slight changes , it gets vectorized and prints the following remarks :
CODE_2
------------------------------------------------------------
---------------------------------------------------------
#include <stdio.h>
int main()
{
int sum[1000]={1,2,3,4};
int x = 0;
for (int i=1;i<1000;i++)
{
x +=sum[i-1];
}
sum[0] = x;
return sum[0];
}
------------------------------------------------------------
------------------------------------------------------------
--------------------
REMARKS_2
------------------------------------------------------------
-------------------------------------------------------------------
test6.c:6:3: remark: vectorized loop (vectorization width: 8, interleaved
count: 4) [-Rpass=loop-vectorize]
for(int i=100;i<1000;i++)
^
------------------------------------------------------------
-------------------------------------------------------------------
Q : Why sum[0] += sum[i-1] is not identified as reduction by LLVM ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180212/4af5602e/attachment.html>
More information about the llvm-dev
mailing list