[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 12 19:10:06 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

LoopStrengthReduce.cpp updated: 1.57 -> 1.58
---
Log message:

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.


---
Diffs of the changes:  (+8 -4)

 LoopStrengthReduce.cpp |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.57 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.58
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.57	Mon Sep 12 12:11:27 2005
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Mon Sep 12 21:09:55 2005
@@ -333,14 +333,14 @@
     Instruction *User = cast<Instruction>(*UI);
 
     // Do not infinitely recurse on PHI nodes.
-    if (isa<PHINode>(User) && User->getParent() == L->getHeader())
+    if (isa<PHINode>(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 @@
   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);






More information about the llvm-commits mailing list