OSDN Git Service

Revert 85634. It's breaking consumer-typeset (and others).
authorEvan Cheng <evan.cheng@apple.com>
Sat, 31 Oct 2009 01:28:06 +0000 (01:28 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 31 Oct 2009 01:28:06 +0000 (01:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85641 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 672ed0a..e1741a0 100644 (file)
@@ -10981,24 +10981,22 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
     }
   }
 
-  // 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) {
+  // 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);
       BasicBlock *BBA = PN.getIncomingBlock(i);
-      BasicBlock *BBB = FirstPN->getIncomingBlock(i);
-      if (BBA != BBB) {
-        Value *VA = PN.getIncomingValue(i);
-        unsigned j = FirstPN->getBasicBlockIndex(BBA);
-        Value *VB = PN.getIncomingValue(j);
-        PN.setIncomingBlock(i, BBB);
-        PN.setIncomingValue(i, VB);
-        PN.setIncomingBlock(j, BBA);
-        PN.setIncomingValue(j, VA);
-      }
+      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);
     }
 
   return 0;