From 95bdbfa0668cc2b475429fbc6046f364bc01edf7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sun, 24 May 2009 19:11:38 +0000 Subject: When rewriting the loop exit test with the canonical induction variable, leave the original comparison in place if it has other uses, since the other uses won't be dominated by the new comparison instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72369 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/IndVarSimplify.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/Transforms') diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index f20d424724..07c7d0071f 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -187,7 +187,12 @@ ICmpInst *IndVarSimplify::LinearFunctionTestReplace(Loop *L, ICmpInst *Cond = new ICmpInst(Opcode, CmpIndVar, ExitCnt, "exitcond", BI); Instruction *OrigCond = cast(BI->getCondition()); - OrigCond->replaceAllUsesWith(Cond); + // It's tempting to use replaceAllUsesWith here to fully replace the old + // comparison, but that's not immediately safe, since users of the old + // comparison may not be dominated by the new comparison. Instead, just + // update the branch to use the new comparison; in the common case this + // will make old comparison dead. + BI->setCondition(Cond); RecursivelyDeleteTriviallyDeadInstructions(OrigCond); ++NumLFTR; -- cgit v1.2.3-70-g09d2