[llvm-dev] Is SCEV unable to determine obvious max trip count?

Nemanja Ivanovic via llvm-dev llvm-dev at lists.llvm.org
Fri Mar 22 11:50:47 PDT 2019


Given a simple test where the maximum trip count is quite obvious, we end
up producing a vectorized loop (or excessively complex control flow)
seemingly because we are unable to determine the maximum trip count of the
loop.
Here's an example:
#ifndef _START
#define _START 3
#endif
unsigned long test(unsigned long *a, unsigned long b) {
  for (unsigned long i = _START; i < (b & 7); i++)
    a[i] = b;
  return b;
}

If we compile that with -D_START=0, the loop is fully unrolled with a
comparison and exit if the result of the and is equal to any of the 7
possible values at each unrolled iteration.
However, if we do not have that define (i.e. loop doesn't start from zero),
we will vectorize the loop. There's even a "min.iters" check that is very
obviously redundant:

%and = and i64 %b, 7
...
%0 = add nsw i64 %and, -3
%min.iters.check = icmp ult i64 %0, 24

The constant here will be different on different targets, but redundant
nonetheless.
Does anyone think this is important to fix this or have any ideas on how to
improve the handling here?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190322/0f4592de/attachment.html>


More information about the llvm-dev mailing list