[llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Jun 16 18:46:04 PDT 2005



Changes in directory llvm/lib/Transforms/Utils:

SimplifyCFG.cpp updated: 1.71 -> 1.72
---
Log message:

Don't crash on:  X = phi (X, X).

This fixes PR584: http://llvm.cs.uiuc.edu/PR584  and Transforms/SimplifyCFG/2005-06-16-PHICrash.ll



---
Diffs of the changes:  (+9 -6)

 SimplifyCFG.cpp |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.71 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.72
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.71	Fri May 20 17:19:54 2005
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp	Thu Jun 16 20:45:53 2005
@@ -1461,12 +1461,15 @@
         BasicBlock::iterator AfterPHIIt = BB->begin();
         while (isa<PHINode>(AfterPHIIt)) {
           PHINode *PN = cast<PHINode>(AfterPHIIt++);
-          if (PN->getIncomingValue(0) == PN->getIncomingValue(1))
-            PN->replaceAllUsesWith(PN->getIncomingValue(0));
-          else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
-                                        &AggressiveInsts) ||
-                   !DominatesMergePoint(PN->getIncomingValue(1), BB,
-                                        &AggressiveInsts)) {
+          if (PN->getIncomingValue(0) == PN->getIncomingValue(1)) {
+            if (PN->getIncomingValue(0) != PN)
+              PN->replaceAllUsesWith(PN->getIncomingValue(0));
+            else
+              PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
+          } else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
+                                          &AggressiveInsts) ||
+                     !DominatesMergePoint(PN->getIncomingValue(1), BB,
+                                          &AggressiveInsts)) {
             CanPromote = false;
             break;
           }






More information about the llvm-commits mailing list