From 396b2baf3ca0ee46e696713d34943035206d7a46 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 13 Sep 2005 02:09:55 +0000 Subject: [PATCH] Fix an issue where LSR would miss rewriting a use of an IV expression by a PHI node that is not the original PHI. This fixes up a dot-product loop in galgel, speeding it up from 18.47s to 16.13s. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23327 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopStrengthReduce.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 1a6ce62102f..8c66e262e40 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -333,14 +333,14 @@ bool LoopStrengthReduce::AddUsersIfInteresting(Instruction *I, Loop *L, Instruction *User = cast(*UI); // Do not infinitely recurse on PHI nodes. - if (isa(User) && User->getParent() == L->getHeader()) + if (isa(User) && Processed.count(User)) continue; // If this is an instruction defined in a nested loop, or outside this loop, // don't recurse into it. bool AddUserToIVUsers = false; if (LI->getLoopFor(User->getParent()) != L) { - DEBUG(std::cerr << "FOUND USER in nested loop: " << *User + DEBUG(std::cerr << "FOUND USER in other loop: " << *User << " OF SCEV: " << *ISE << "\n"); AddUserToIVUsers = true; } else if (!AddUsersIfInteresting(User, L, Processed)) { @@ -459,9 +459,13 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEVHandle &NewBase, for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { if (PN->getIncomingValue(i) == OperandValToReplace) { // If this is a critical edge, split the edge so that we do not insert the - // code on all predecessor/successor paths. + // code on all predecessor/successor paths. We do this unless this is the + // canonical backedge for this loop, as this can make some inserted code + // be in an illegal position. if (e != 1 && - PN->getIncomingBlock(i)->getTerminator()->getNumSuccessors() > 1) { + PN->getIncomingBlock(i)->getTerminator()->getNumSuccessors() > 1 && + (PN->getParent() != L->getHeader() || + !L->contains(PN->getIncomingBlock(i)))) { // First step, split the critical edge. SplitCriticalEdge(PN->getIncomingBlock(i), PN->getParent(), P);