[llvm-commits] [llvm] r85655 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Dan Gohman gohman at apple.com
Sat Oct 31 07:22:52 PDT 2009


Author: djg
Date: Sat Oct 31 09:22:52 2009
New Revision: 85655

URL: http://llvm.org/viewvc/llvm-project?rev=85655&view=rev
Log:
Reapply r85634, with the bug fixed.

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=85655&r1=85654&r2=85655&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sat Oct 31 09:22:52 2009
@@ -10981,22 +10981,24 @@
     }
   }
 
-  // Sort the PHI node operands to match the pred iterator order. This will
-  // help identical PHIs be eliminated by other passes. Other passes shouldn't
-  // depend on this for correctness however.
-  unsigned i = 0;
-  for (pred_iterator PI = pred_begin(PN.getParent()),
-       PE = pred_end(PN.getParent()); PI != PE; ++PI, ++i)
-    if (PN.getIncomingBlock(i) != *PI) {
-      unsigned j = PN.getBasicBlockIndex(*PI);
-      Value *VA = PN.getIncomingValue(i);
+  // If there are multiple PHIs, sort their operands so that they all list
+  // the blocks in the same order. This will help identical PHIs be eliminated
+  // by other passes. Other passes shouldn't depend on this for correctness
+  // however.
+  PHINode *FirstPN = cast<PHINode>(PN.getParent()->begin());
+  if (&PN != FirstPN)
+    for (unsigned i = 0, e = FirstPN->getNumIncomingValues(); i != e; ++i) {
       BasicBlock *BBA = PN.getIncomingBlock(i);
-      Value *VB = PN.getIncomingValue(j);
-      BasicBlock *BBB = PN.getIncomingBlock(j);
-      PN.setIncomingBlock(i, BBB);
-      PN.setIncomingValue(i, VB);
-      PN.setIncomingBlock(j, BBA);
-      PN.setIncomingValue(j, VA);
+      BasicBlock *BBB = FirstPN->getIncomingBlock(i);
+      if (BBA != BBB) {
+        Value *VA = PN.getIncomingValue(i);
+        unsigned j = PN.getBasicBlockIndex(BBB);
+        Value *VB = PN.getIncomingValue(j);
+        PN.setIncomingBlock(i, BBB);
+        PN.setIncomingValue(i, VB);
+        PN.setIncomingBlock(j, BBA);
+        PN.setIncomingValue(j, VA);
+      }
     }
 
   return 0;





More information about the llvm-commits mailing list