OSDN Git Service

[LoopIdiomRecognize] Add a test case to show incorrect transformation of an infinite...
authorCraig Topper <craig.topper@intel.com>
Thu, 3 May 2018 23:50:29 +0000 (23:50 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 3 May 2018 23:50:29 +0000 (23:50 +0000)
commit013b5ae046d55ad6c09587aae96123e8a2ffff56
tree7db81ee38a73694f01b3c9331b1d9ed72d1deff0
parent220e35cb11cbecabbd5863f4cabf7a7417b62d21
[LoopIdiomRecognize] Add a test case to show incorrect transformation of an infinite loop with side effets into a countable loop using ctlz.

We currently recognize this idiom where x is signed and thus the shift in an ashr.

int cnt = 0;
while (x) {
  x >>= 1; // arithmetic shift right
  ++cnt;
}

and turn it into (bitwidth - ctlz(x)). And if there is anything else in the loop we will create a new loop that runs that many times.

If x is initially negative, the shift result will never be 0 and thus the loop is infinite. If you put something with side effects in the loop, that side effect will now only happen bitwidth times instead of an infinite number of times.

So this transform is only safe for logical shift right (which we don't currently recognize) or if we can prove that x cannot be negative before the loop.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331493 91177308-0d34-0410-b5e6-96231b3b80d8
test/Transforms/LoopIdiom/X86/ctlz.ll