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

Dan Gohman gohman at apple.com
Fri Oct 30 15:22:22 PDT 2009


Author: djg
Date: Fri Oct 30 17:22:22 2009
New Revision: 85623

URL: http://llvm.org/viewvc/llvm-project?rev=85623&view=rev
Log:
Sort the incoming values in PHI nodes to match the predecessor order.
This helps expose duplicate PHIs, which will make it easier for them
to be eliminated.

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=85623&r1=85622&r2=85623&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri Oct 30 17:22:22 2009
@@ -10980,6 +10980,25 @@
       }
     }
   }
+
+  // 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);
+      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;
 }
 





More information about the llvm-commits mailing list