aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-05-27 21:10:47 +0000
committerDan Gohman <gohman@apple.com>2009-05-27 21:10:47 +0000
commit5482b98d8f6581f1900a3c890d823ca1b5150851 (patch)
tree9c84f7b55133a8f66c4b88fb694b3509ac6695ac
parent3e295dccc9962f7cea1f138c146feb737b579ed7 (diff)
downloadexternal_llvm-5482b98d8f6581f1900a3c890d823ca1b5150851.zip
external_llvm-5482b98d8f6581f1900a3c890d823ca1b5150851.tar.gz
external_llvm-5482b98d8f6581f1900a3c890d823ca1b5150851.tar.bz2
Revert 72493 and replace it with a more conservative fix, for now: don't
rewrite the comparison if there is any implicit extension or truncation on the induction variable. I'm planning for IVUsers to eventually take over some of the work of this code, and for it to be generalized. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72496 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp15
-rw-r--r--test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-2.ll25
2 files changed, 33 insertions, 7 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 834a95d..92270b5 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1993,6 +1993,12 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
ValidScale(!CommonExprs->isZero(), Scale, UsersToProcess))
continue;
+ // Avoid rewriting the compare instruction with an iv which has
+ // implicit extension or truncation built into it.
+ // TODO: This is over-conservative.
+ if (SE->getTypeSizeInBits(CondUse->getOffset()->getType()) != TyBits)
+ continue;
+
// If scale is negative, use swapped predicate unless it's testing
// for equality.
if (Scale < 0 && !Cond->isEquality())
@@ -2005,16 +2011,11 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
ConstantInt *CI = ConstantInt::get(NewCmpIntTy, NewCmpVal);
NewCmpRHS = ConstantExpr::getIntToPtr(CI, NewCmpTy);
}
- NewOffset = CondUse->getOffset();
- if (CondUse->isSigned())
- NewOffset = SE->getNoopOrSignExtend(CondUse->getOffset(), NewCmpTy);
- else
- NewOffset = SE->getNoopOrZeroExtend(CondUse->getOffset(), NewCmpTy);
NewOffset = TyBits == NewTyBits
- ? SE->getMulExpr(NewOffset,
+ ? SE->getMulExpr(CondUse->getOffset(),
SE->getConstant(ConstantInt::get(CmpTy, Scale)))
: SE->getConstant(ConstantInt::get(NewCmpIntTy,
- cast<SCEVConstant>(NewOffset)->getValue()
+ cast<SCEVConstant>(CondUse->getOffset())->getValue()
->getSExtValue()*Scale));
break;
}
diff --git a/test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-2.ll b/test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-2.ll
index e3cb3a5..f77aea3 100644
--- a/test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-2.ll
+++ b/test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness-2.ll
@@ -31,3 +31,28 @@ if.end52: ; preds = %for.cond.i.preheader
%indvar.next689 = add i64 %indvar688, 1 ; <i64> [#uses=1]
br i1 %phitmp654, label %for.cond.i.preheader, label %if.end
}
+
+define void @promote(%struct.dumperinfo* %di) nounwind {
+entry:
+ br label %if.end
+
+if.end: ; preds = %if.end52, %entry
+ br label %for.cond.i.preheader
+
+for.cond.i.preheader: ; preds = %if.end52, %if.end
+ %indvar688 = phi i32 [ 0, %if.end ], [ %indvar.next689, %if.end52 ] ; <i64> [#uses=3]
+ %tmp690 = shl i32 %indvar688, 12 ; <i64> [#uses=1]
+ %pa.0642 = add i32 %tmp690, 0 ; <i64> [#uses=1]
+ %tmp692693 = add i32 %indvar688, 1 ; <i32> [#uses=1]
+ %phitmp = sext i32 %tmp692693 to i64 ; <i64> [#uses=1]
+ br i1 false, label %if.end52, label %land.lhs.true.i
+
+land.lhs.true.i: ; preds = %for.cond.i.preheader
+ %shr2.i = lshr i32 %pa.0642, 18 ; <i64> [#uses=0]
+ unreachable
+
+if.end52: ; preds = %for.cond.i.preheader
+ %phitmp654 = icmp ult i64 %phitmp, 512 ; <i1> [#uses=1]
+ %indvar.next689 = add i32 %indvar688, 1 ; <i64> [#uses=1]
+ br i1 %phitmp654, label %for.cond.i.preheader, label %if.end
+}