Bugfix: SCEVExpander incorrectly marks increment operations as no-wrap
authorSanjoy Das <sanjoy@playingwithpointers.com>
Mon, 23 Feb 2015 23:22:58 +0000 (23:22 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Mon, 23 Feb 2015 23:22:58 +0000 (23:22 +0000)
commit8d16a81c331e641b12464d32a0c35d819ab1b5ee
tree82c020e7bcaa6efe02e0bb89c8f5c8102fa70679
parent69048edf8a37372191e833f74f124bb1755dc21b
Bugfix: SCEVExpander incorrectly marks increment operations as no-wrap

When emitting the increment operation, SCEVExpander marks the
operation as nuw or nsw based on the flags on the preincrement SCEV.
This is incorrect because, for instance, it is possible that {-6,+,1}
is <nuw> while {-6,+,1}+1 = {-5,+,1} is not.

This change teaches SCEV to mark the increment as nuw/nsw only if it
can explicitly prove that the increment operation won't overflow.

Apart from the attached test case, another (more realistic) manifestation
of the bug can be seen in Transforms/IndVarSimplify/pr20680.ll.

NOTE: this change was landed with an incorrect commit message in
rL230275 and was reverted for that reason in rL230279.  This commit
message is the correct one.

Differential Revision: http://reviews.llvm.org/D7778

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230280 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ScalarEvolutionExpander.cpp
test/Analysis/ScalarEvolution/scev-expander-incorrect-nowrap.ll [new file with mode: 0644]
test/Analysis/ScalarEvolution/zext-signed-addrec.ll
test/CodeGen/AArch64/arm64-scaled_iv.ll
test/CodeGen/X86/avoid_complex_am.ll
test/Transforms/IndVarSimplify/overflowcheck.ll
test/Transforms/IndVarSimplify/pr20680.ll
test/Transforms/LoopStrengthReduce/count-to-zero.ll
test/Transforms/LoopStrengthReduce/uglygep.ll