[LLVMdev] Missed vectorization opportunities?

Daniel Berlin dberlin at dberlin.org
Wed Apr 22 08:29:11 PDT 2015


> 2. Of the two loops below, the loop "works" gets vectorized, while the loop
> "fails" does not get vectorized.
> #define SIZE 10000
> int a[SIZE+4] = {};
> void works(unsigned long m, unsigned long n)
> {
>   long j;
>   // SCEV can compute the exit value for this loop
>   for (j = m; j < n+1; j += 1) {
>     a[j] = a[j+1] + 2;
>   }
> }
> void fails(unsigned long m, unsigned long n)
> {
>   long j;
>   // SCEV cannot compute the exit value for this loop
>   for (j = m; j <= n; j += 1) {
>     a[j] = a[j+1] + 2;
>   }
> }
>
> The only difference between the two loops is the loop exit condition, both
> semantically same.


I expect SCEV treats them differently because of MAX_INT handling.
Look as the definedness of both if n == MAX_INT. The first has
undefined behavior, the second does not.
If you change the second into the first, you introduce undefined behavior.
(or maybe it's implementation defined, but whatever)


This is the:
  if (!getUnsignedRange(RHS).getUnsignedMax().isMaxValue()) {

check in that function simplify.

But you should file a bug anyway.



More information about the llvm-dev mailing list