[llvm-commits] [llvm] r85634 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Evan Cheng
evan.cheng at apple.com
Fri Oct 30 20:11:33 PDT 2009
Hi Dan,
This is breaking consumer-typeset (and other tests). I've reverted it
for now.
Evan
On Oct 30, 2009, at 4:15 PM, Dan Gohman wrote:
> Author: djg
> Date: Fri Oct 30 18:15:21 2009
> New Revision: 85634
>
> URL: http://llvm.org/viewvc/llvm-project?rev=85634&view=rev
> Log:
> 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.
>
> 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=85634&r1=85633&r2=85634&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Fri
> Oct 30 18:15:21 2009
> @@ -10981,22 +10981,24 @@
> }
> }
>
> - // 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;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list