From 4486da5b78b47dc3c947ceb634d13a3d0ff0889e 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. llvm-svn: 72369 --- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index f20d424724a..07c7d0071fb 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/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