Bugfix: SCEVExpander incorrectly marks increment operations as no-wrap
authorSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 25 Feb 2015 20:02:59 +0000 (20:02 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Wed, 25 Feb 2015 20:02:59 +0000 (20:02 +0000)
commita0a0b40aa395ea711878a5e638db8a419144ab73
tree68f599ec33b52f238e11dc831e2963b2ba55fa2b
parenta40d4ae47869167fc8cdfa88c041dca93154ef04
Bugfix: SCEVExpander incorrectly marks increment operations as no-wrap

(The change was landed in r230280 and caused the regression PR22674.
This version contains a fix and a test-case for PR22674).

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.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230533 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ScalarEvolutionExpander.cpp
test/Analysis/ScalarEvolution/pr22674.ll [new file with mode: 0644]
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