[llvm-commits] [llvm] r60325 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
Chris Lattner
sabre at nondot.org
Sun Nov 30 19:42:52 PST 2008
Author: lattner
Date: Sun Nov 30 21:42:51 2008
New Revision: 60325
URL: http://llvm.org/viewvc/llvm-project?rev=60325&view=rev
Log:
Change instcombine to use FoldPHIArgGEPIntoPHI to fold two operand PHIs
instead of using FoldPHIArgBinOpIntoPHI. In addition to being more
obvious, this also fixes a problem where instcombine wouldn't merge two
phis that had different variable indices. This prevented instcombine
from factoring big chunks of code in 403.gcc. For example:
insn_cuid.exit:
- %tmp336 = load i32** @uid_cuid, align 4
- %tmp337 = getelementptr %struct.rtx_def* %insn_addr.0.ph.i, i32 0, i32 3
- %tmp338 = bitcast [1 x %struct.rtunion]* %tmp337 to i32*
- %tmp339 = load i32* %tmp338, align 4
- %tmp340 = getelementptr i32* %tmp336, i32 %tmp339
br label %bb62
bb61:
- %tmp341 = load i32** @uid_cuid, align 4
- %tmp342 = getelementptr %struct.rtx_def* %insn, i32 0, i32 3
- %tmp343 = bitcast [1 x %struct.rtunion]* %tmp342 to i32*
- %tmp344 = load i32* %tmp343, align 4
- %tmp345 = getelementptr i32* %tmp341, i32 %tmp344
br label %bb62
bb62:
- %iftmp.62.0.in = phi i32* [ %tmp345, %bb61 ], [ %tmp340, %insn_cuid.exit ]
+ %insn.pn2 = phi %struct.rtx_def* [ %insn, %bb61 ], [ %insn_addr.0.ph.i, %insn_cuid.exit ]
+ %tmp344.pn.in.in = getelementptr %struct.rtx_def* %insn.pn2, i32 0, i32 3
+ %tmp344.pn.in = bitcast [1 x %struct.rtunion]* %tmp344.pn.in.in to i32*
+ %tmp341.pn = load i32** @uid_cuid
+ %tmp344.pn = load i32* %tmp344.pn.in
+ %iftmp.62.0.in = getelementptr i32* %tmp341.pn, i32 %tmp344.pn
%iftmp.62.0 = load i32* %iftmp.62.0.in
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=60325&r1=60324&r2=60325&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Nov 30 21:42:51 2008
@@ -9975,8 +9975,7 @@
/// and a single binop.
Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
Instruction *FirstInst = cast<Instruction>(PN.getIncomingValue(0));
- assert(isa<BinaryOperator>(FirstInst) || isa<GetElementPtrInst>(FirstInst) ||
- isa<CmpInst>(FirstInst));
+ assert(isa<BinaryOperator>(FirstInst) || isa<CmpInst>(FirstInst));
unsigned Opc = FirstInst->getOpcode();
Value *LHSVal = FirstInst->getOperand(0);
Value *RHSVal = FirstInst->getOperand(1);
@@ -10006,14 +10005,7 @@
if (I->getOperand(1) != RHSVal) RHSVal = 0;
}
- // Otherwise, this is safe to transform, determine if it is profitable.
-
- // If this is a GEP, and if the index (not the pointer) needs a PHI, bail out.
- // Indexes are often folded into load/store instructions, so we don't want to
- // hide them behind a phi.
- // URR??
- if (isa<GetElementPtrInst>(FirstInst) && RHSVal == 0)
- return 0;
+ // Otherwise, this is safe to transform!
Value *InLHS = FirstInst->getOperand(0);
Value *InRHS = FirstInst->getOperand(1);
@@ -10053,11 +10045,9 @@
if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst))
return BinaryOperator::Create(BinOp->getOpcode(), LHSVal, RHSVal);
- if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst))
- return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), LHSVal,
- RHSVal);
- assert(isa<GetElementPtrInst>(FirstInst));
- return GetElementPtrInst::Create(LHSVal, RHSVal);
+ CmpInst *CIOp = cast<CmpInst>(FirstInst);
+ return CmpInst::Create(CIOp->getOpcode(), CIOp->getPredicate(), LHSVal,
+ RHSVal);
}
Instruction *InstCombiner::FoldPHIArgGEPIntoPHI(PHINode &PN) {
@@ -10207,8 +10197,6 @@
return 0;
} else if (isa<GetElementPtrInst>(FirstInst)) {
- if (FirstInst->getNumOperands() == 2)
- return FoldPHIArgBinOpIntoPHI(PN);
return FoldPHIArgGEPIntoPHI(PN);
} else {
return 0; // Cannot fold this operation.
More information about the llvm-commits
mailing list