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

Chris Lattner lattner at cs.uiuc.edu
Fri Jun 16 18:02:44 PDT 2006



Changes in directory llvm/lib/Transforms/Scalar:

IndVarSimplify.cpp updated: 1.82 -> 1.83
---
Log message:

Fix IndVarsSimplify/2006-06-16-Indvar-LCSSA-Crash.ll, a case where a 
"LCSSA" phi node causes indvars to break dominance properties.  This fixes
causes indvars to avoid inserting aggressive code in this case, instead
indvars should be fixed to be more aggressive in the face of lcssa phi's.


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

 IndVarSimplify.cpp |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)


Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.82 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.83
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.82	Fri Nov 18 12:30:47 2005
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp	Fri Jun 16 20:02:31 2006
@@ -321,11 +321,26 @@
               HasConstantItCount) {
             // Find out if this predictably varying value is actually used
             // outside of the loop.  "extra" as opposed to "intra".
-            std::vector<User*> ExtraLoopUsers;
+            std::vector<Instruction*> ExtraLoopUsers;
             for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
-                 UI != E; ++UI)
-              if (!L->contains(cast<Instruction>(*UI)->getParent()))
-                ExtraLoopUsers.push_back(*UI);
+                 UI != E; ++UI) {
+              Instruction *User = cast<Instruction>(*UI);
+              if (!L->contains(User->getParent())) {
+                // If this is a PHI node in the exit block and we're inserting,
+                // into the exit block, it must have a single entry.  In this
+                // case, we can't insert the code after the PHI and have the PHI
+                // still use it.  Instead, don't insert the the PHI.
+                if (PHINode *PN = dyn_cast<PHINode>(User)) {
+                  // FIXME: This is a case where LCSSA pessimizes code, this
+                  // should be fixed better.
+                  if (PN->getNumOperands() == 2 && 
+                      PN->getParent() == BlockToInsertInto)
+                    continue;
+                }
+                ExtraLoopUsers.push_back(User);
+              }
+            }
+            
             if (!ExtraLoopUsers.empty()) {
               // Okay, this instruction has a user outside of the current loop
               // and varies predictably in this loop.  Evaluate the value it






More information about the llvm-commits mailing list