[LLVMdev] Missed vectorization opportunities?

Vaivaswatha N vaivaswatha at yahoo.co.in
Wed Apr 22 04:01:05 PDT 2015


Hi,
I am trying to understand the limitations of the current vectorizer, and came upon these test cases that fail to get vectorized.
1. loop1 below (note the increment by 2) fails to get vectorized because the access a[j+1] is considered to wrap around (the corresponding SCEV doesn't have nsw/nuw set) and hence isStridedPtr() in LoopAccessAnalysis.cpp return false. 

#define SIZE 100000
void loop1 (float a[SIZE])
{
  long t, j;
  float cc = 23, dd = 34, ee = 233;
#pragma clang loop vectorize(enable)
  for (j = 1; j < SIZE-1; j += 2) {
    float x;
    x = a[j+1] + ee;
    x = x / dd;
    x = (cc + x) / dd;
    a[j] = x + 2 ;
  }
}

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. Scalar Evolution is unable to determine the exit value of the second loop, leading to the vectorizer failing to vectorize. It seemed to me that this is due to ScalarEvolution::SimplifyICmpOperands failing to canonicalize the corresponding ICMP_ULE instruction.
Thanks,
- Vaivaswatha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150422/41a73399/attachment.html>


More information about the llvm-dev mailing list