[llvm-commits] [llvm] r54786 - in /llvm/trunk: lib/Transforms/Scalar/LoopStrengthReduce.cpp test/Transforms/LoopStrengthReduce/2008-08-14-ShadowIV.ll

Eli Friedman eli.friedman at gmail.com
Thu Aug 14 21:31:17 PDT 2008


This patch doesn't handle overflow correctly.

Take the following, where the iteration count is very large (greater than 2^32):
unsigned y(double);
unsigned z();
unsigned x() {
  unsigned x = 0;
  for ( ; z(); x++) y(x);
}
The transformation is unsafe because x is supposed to overflow.

or the following, where a is very large (greater than around 2^23):
void y(float);
unsigned x(unsigned a) {
  unsigned i = 0;
  for ( ; i < a; i++) y(i);
}
The transformation is unsafe because the float induction variable will
eventually stop increasing.

It is possible to prove this transformation safe (for example, the
transformation is safe for 2008-08-14-ShadowIV.ll because the mantissa
of double is greater than 32 bits and the iteration count is %n <
2^32), but as-is, this commit breaks correct code.


I'm not sure if this is related to the patch, but one testcase I was
trying that I expected to trigger the new code didn't end up
triggering it, for reasons I haven't yet figured out:

unsigned y(double);
unsigned x(unsigned long long a) {
  unsigned long long i = 0;
  unsigned x = 0;
  for ( ; i < a; x++, i++) y(x);
}

-Eli



More information about the llvm-commits mailing list