diff options
| author | Dan Gohman <gohman@apple.com> | 2009-09-16 16:50:24 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2009-09-16 16:50:24 +0000 |
| commit | bd0050810c466ee5023e5409de3972373ec9ce5a (patch) | |
| tree | 9cc4560375487ad7ff92aab483e422118bce47ea | |
| parent | 4141deb68e4cc3d2b7d4c8b16caa15c8b71c3e6b (diff) | |
| download | bcm5719-llvm-bd0050810c466ee5023e5409de3972373ec9ce5a.tar.gz bcm5719-llvm-bd0050810c466ee5023e5409de3972373ec9ce5a.zip | |
Change FoldPHIArgBinOpIntoPHI to decline folding if it would introduce two
phis, similar to the FoldPHIArgGEPIntoPHI change.
Also, delete some comments that don't reflect the code.
llvm-svn: 82053
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 006d67b6034..e6bd1929767 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -10313,8 +10313,8 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { return CS.getInstruction(); } -/// FoldPHIArgBinOpIntoPHI - If we have something like phi [add (a,b), add(c,d)] -/// and if a/b/c/d and the add's all have a single use, turn this into two phi's +/// FoldPHIArgBinOpIntoPHI - If we have something like phi [add (a,b), add(a,c)] +/// and if a/b/c and the add's all have a single use, turn this into a phi /// and a single binop. Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { Instruction *FirstInst = cast<Instruction>(PN.getIncomingValue(0)); @@ -10326,8 +10326,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { const Type *LHSType = LHSVal->getType(); const Type *RHSType = RHSVal->getType(); - // Scan to see if all operands are the same opcode, all have one use, and all - // kill their operands (i.e. the operands have one use). + // Scan to see if all operands are the same opcode, and all have one use. for (unsigned i = 1; i != PN.getNumIncomingValues(); ++i) { Instruction *I = dyn_cast<Instruction>(PN.getIncomingValue(i)); if (!I || I->getOpcode() != Opc || !I->hasOneUse() || @@ -10347,6 +10346,13 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { if (I->getOperand(0) != LHSVal) LHSVal = 0; if (I->getOperand(1) != RHSVal) RHSVal = 0; } + + // If both LHS and RHS would need a PHI, don't do this transformation, + // because it would increase the number of PHIs entering the block, + // which leads to higher register pressure. This is especially + // bad when the PHIs are in the header of a loop. + if (!LHSVal && !RHSVal) + return 0; // Otherwise, this is safe to transform! @@ -10403,11 +10409,11 @@ Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) { bool AllBasePointersAreAllocas = true; // We don't want to replace this phi if the replacement would require - // more than one phi. + // more than one phi, which leads to higher register pressure. This is + // especially bad when the PHIs are in the header of a loop. bool NeededPhi = false; - // Scan to see if all operands are the same opcode, all have one use, and all - // kill their operands (i.e. the operands have one use). + // Scan to see if all operands are the same opcode, and all have one use. for (unsigned i = 1; i != PN.getNumIncomingValues(); ++i) { GetElementPtrInst *GEP= dyn_cast<GetElementPtrInst>(PN.getIncomingValue(i)); if (!GEP || !GEP->hasOneUse() || GEP->getType() != FirstInst->getType() || |

