aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-06-13 21:43:41 +0000
committerDan Gohman <gohman@apple.com>2008-06-13 21:43:41 +0000
commite562b1725ee068ff525082d1e9ba885c8928c72e (patch)
tree9b72fd57418359f66f6cf908fe0323d13befa225 /lib/Transforms
parent66fe80aa57c6de0b48fb4efb4c7bebe35c6c28c8 (diff)
Protect ChangeCompareStride from situations in which it is possible
for it to generate use-before-def IR, such as in this testcase. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index cc5da5dd53..1955fa5aa8 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -1529,6 +1529,15 @@ namespace {
ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
IVStrideUse* &CondUse,
const SCEVHandle* &CondStride) {
+ // Forgo this transformation if the condition has multiple uses. This is
+ // over-conservative, but simpler than alternatives. It guards against
+ // comparisons with a use that occurs earlier than the add instruction for the
+ // new stride index. See
+ // test/Transforms/LoopStrengthReduce/change-compare-stride-trickiness.ll
+ // for an example of this situation.
+ if (!Cond->hasOneUse())
+ return Cond;
+
if (StrideOrder.size() < 2 ||
IVUsesByStride[*CondStride].Users.size() != 1)
return Cond;
@@ -1654,9 +1663,9 @@ ICmpInst *LoopStrengthReduce::ChangeCompareStride(Loop *L, ICmpInst *Cond,
RHS = SCEVExpander::InsertCastOfTo(Instruction::IntToPtr, RHS, NewCmpTy);
}
// Insert new compare instruction.
- Cond = new ICmpInst(Predicate, NewIncV, RHS);
- Cond->setName(L->getHeader()->getName() + ".termcond");
- OldCond->getParent()->getInstList().insert(OldCond, Cond);
+ Cond = new ICmpInst(Predicate, NewIncV, RHS,
+ L->getHeader()->getName() + ".termcond",
+ OldCond);
// Remove the old compare instruction. The old indvar is probably dead too.
DeadInsts.insert(cast<Instruction>(CondUse->OperandValToReplace));