[LLVMdev] loop vectorizer issue
Gregory Junker
gjunker at dayark.com
Sun Nov 3 18:53:35 PST 2013
On 11/3/2013 10:39 AM, Sara Elshobaky wrote:
> Actually what I meant in my original loop, that there is a dependency
> between every two consecutive iterations. So, how the loop vectorizer
> says ‘we can vectorize this loop’?
>
> for(int k=20;k<50;k++)
>
> dataY[k] = dataY[k-1];
The reason that this is equivalent to
> int a = d[19];
> for(int k = 20; k < 50; k++)
> dataY[k] = a;
may not be immediately clear. But if you manually unroll the original
loop it may make more sense. So your loop, fully unrolled, would look like
dataY[20] = dataY[19];
dataY[21] = dataY[20];
dataY[22] = dataY[21];
...
dataY[49] = dataY[48];
From this you should be able to see that after you have run the 30
iterations, all of the LHS values (in other words, this whole section of
the dataY array) will end up with the same value that is in dataY[19].
That is why the compiler can make this optimization.
Does that make sense?
Greg
More information about the llvm-dev
mailing list