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 | 8e42e4baaea4c9252eba39a4bcf4f295ebd8c78a (patch) | |
tree | 81ef2bef0be4428fd4d7ce27a91c5359e1e15cdd | |
parent | 0115e164bad632572e2cfbaf72f0f0882d5319de (diff) | |
download | external_llvm-8e42e4baaea4c9252eba39a4bcf4f295ebd8c78a.zip external_llvm-8e42e4baaea4c9252eba39a4bcf4f295ebd8c78a.tar.gz external_llvm-8e42e4baaea4c9252eba39a4bcf4f295ebd8c78a.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85623 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 0ca3114..e1741a0 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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; } |