diff options
author | Dan Gohman <gohman@apple.com> | 2009-10-30 22:22:22 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-10-30 22:22:22 +0000 |
commit | 13e41edc7165f7d3b6ac7b23d0190791f19f67fd (patch) | |
tree | ede326672c3223e03dc5d33b88f4345c6c2a97e3 /llvm/lib | |
parent | 49fa51d936220a84e3561405e32915da272cf847 (diff) | |
download | bcm5719-llvm-13e41edc7165f7d3b6ac7b23d0190791f19f67fd.tar.gz bcm5719-llvm-13e41edc7165f7d3b6ac7b23d0190791f19f67fd.zip |
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.
llvm-svn: 85623
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 0ca3114c44d..e1741a00676 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10980,6 +10980,25 @@ 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); + 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; } |