summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
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
commit9ad8c54aab51afec95ae4989e36850cddf40b606 (patch)
tree2c619672985f81a97513c55bb5b9572271ac7a55 /llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
parent9833a1b4071d5cdbf8a938083ea90a70008f8f9c (diff)
downloadbcm5719-llvm-9ad8c54aab51afec95ae4989e36850cddf40b606.tar.gz
bcm5719-llvm-9ad8c54aab51afec95ae4989e36850cddf40b606.zip
Protect ChangeCompareStride from situations in which it is possible
for it to generate use-before-def IR, such as in this testcase. llvm-svn: 52258
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index cc5da5dd538..1955fa5aa84 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/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));
OpenPOWER on IntegriCloud