summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-10-30 23:15:21 +0000
committerDan Gohman <gohman@apple.com>2009-10-30 23:15:21 +0000
commit5bec30ca5d5d3d74f7cd899dbafed7b82ca4a3fc (patch)
tree535d9413c70e6fbbbe350a766e31973a7460c44f
parent326b2fa03ed4715a4fccf2615dd6320528602dd0 (diff)
downloadbcm5719-llvm-5bec30ca5d5d3d74f7cd899dbafed7b82ca4a3fc.tar.gz
bcm5719-llvm-5bec30ca5d5d3d74f7cd899dbafed7b82ca4a3fc.zip
Optimize around the fact that pred_iterator is slow: instead of sorting
PHI operands by the predecessor order, sort them by the order used by the first PHI in the block. This is still suffucient to expose duplicates. llvm-svn: 85634
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index e1741a00676..672ed0af1ba 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -10981,22 +10981,24 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
}
}
- // 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 = FirstPN->getBasicBlockIndex(BBA);
+ Value *VB = PN.getIncomingValue(j);
+ PN.setIncomingBlock(i, BBB);
+ PN.setIncomingValue(i, VB);
+ PN.setIncomingBlock(j, BBA);
+ PN.setIncomingValue(j, VA);
+ }
}
return 0;
OpenPOWER on IntegriCloud