summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2008-08-13 02:05:14 +0000
committerDevang Patel <dpatel@apple.com>2008-08-13 02:05:14 +0000
commit97387e6615c7e8fe8a941b2af4bfa6c5bdc5e5a9 (patch)
treecd6dbb6cd9dc1aa6670b5ee0d5d46fd485d43e7b /llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
parent89da6ad1db120f53437de8800f8cd6de532a8003 (diff)
downloadbcm5719-llvm-97387e6615c7e8fe8a941b2af4bfa6c5bdc5e5a9.tar.gz
bcm5719-llvm-97387e6615c7e8fe8a941b2af4bfa6c5bdc5e5a9.zip
Check sign to detect overflow before changing compare stride.
llvm-svn: 54710
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 3d82fd279c5..f47a5afcfc5 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1542,6 +1542,12 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
Value *NewIncV = NULL;
int64_t Scale = 1;
+ // Check stride constant and the comparision constant signs to detect
+ // overflow.
+ if (ICmpInst::isSignedPredicate(Predicate) &&
+ (CmpVal & SignBit) != (CmpSSInt & SignBit))
+ return Cond;
+
// Look for a suitable stride / iv as replacement.
std::stable_sort(StrideOrder.begin(), StrideOrder.end(), StrideCompare());
for (unsigned i = 0, e = StrideOrder.size(); i != e; ++i) {
@@ -1640,11 +1646,12 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
// before the branch. See
// test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-*.ll
// for an example of this situation.
- if (!Cond->hasOneUse())
+ if (!Cond->hasOneUse()) {
for (BasicBlock::iterator I = Cond, E = Cond->getParent()->end();
I != E; ++I)
if (I == NewIncV)
return Cond;
+ }
if (NewCmpVal != CmpVal) {
// Create a new compare instruction using new stride / iv.
OpenPOWER on IntegriCloud