[LoopIdiom] 'arithmetic right-shift until zero': don't turn potentially infinite...
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 May 2021 17:47:53 +0000 (20:47 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 25 May 2021 18:02:28 +0000 (21:02 +0300)
commit149e018d12642cf8cda9b26f2ffc66a63cc3cc25
tree90893c1b6c64cadf2befb22f80e15e6de92cb98f
parent8e30b55c82cc245f8b59ef3b29d95c9797584b63
[LoopIdiom] 'arithmetic right-shift until zero': don't turn potentially infinite loops into finite ones

Nowadays LLVM does not assume that all loops are finite,
so if we want to produce a finite loop from a potentially-infinite one,
we must ensure that the original loop is known to be a finite one.

For this transform, it only matters for arithmetic right-shifts.
For them, either the function or the loop must be known to
be `mustprogress`, or the original value being shifted must be known
to be non-negative (because iff the sign bit was set,
it will never become zero, but will become `-1` in the "end").

It would be really good for alive2 to actually complain about this,
but it currently does not: https://github.com/AliveToolkit/alive2/issues/726
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
llvm/test/Transforms/LoopIdiom/X86/arithmetic-right-shift-until-zero.ll