mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-04 02:24:29 +00:00
This optimization makes MANY phi nodes that all have the same incoming value.
If this happens, detect it early instead of relying on instcombine to notice it later. This can be a big speedup, because PHI nodes can have many incoming values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17741 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -3456,21 +3456,37 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) {
|
|||||||
PHINode *NewPN = new PHINode(FirstInst->getOperand(0)->getType(),
|
PHINode *NewPN = new PHINode(FirstInst->getOperand(0)->getType(),
|
||||||
PN.getName()+".in");
|
PN.getName()+".in");
|
||||||
NewPN->op_reserve(PN.getNumOperands());
|
NewPN->op_reserve(PN.getNumOperands());
|
||||||
InsertNewInstBefore(NewPN, PN);
|
|
||||||
|
Value *InVal = FirstInst->getOperand(0);
|
||||||
|
NewPN->addIncoming(InVal, PN.getIncomingBlock(0));
|
||||||
|
|
||||||
// Add all operands to the new PHI.
|
// Add all operands to the new PHI.
|
||||||
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
|
for (unsigned i = 1, e = PN.getNumIncomingValues(); i != e; ++i) {
|
||||||
NewPN->addIncoming(cast<Instruction>(PN.getIncomingValue(i))->getOperand(0),
|
Value *NewInVal = cast<Instruction>(PN.getIncomingValue(i))->getOperand(0);
|
||||||
PN.getIncomingBlock(i));
|
if (NewInVal != InVal)
|
||||||
|
InVal = 0;
|
||||||
|
NewPN->addIncoming(NewInVal, PN.getIncomingBlock(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
Value *PhiVal;
|
||||||
|
if (InVal) {
|
||||||
|
// The new PHI unions all of the same values together. This is really
|
||||||
|
// common, so we handle it intelligently here for compile-time speed.
|
||||||
|
PhiVal = InVal;
|
||||||
|
delete NewPN;
|
||||||
|
} else {
|
||||||
|
InsertNewInstBefore(NewPN, PN);
|
||||||
|
PhiVal = NewPN;
|
||||||
|
}
|
||||||
|
|
||||||
// Insert and return the new operation.
|
// Insert and return the new operation.
|
||||||
if (isa<CastInst>(FirstInst))
|
if (isa<CastInst>(FirstInst))
|
||||||
return new CastInst(NewPN, PN.getType());
|
return new CastInst(PhiVal, PN.getType());
|
||||||
else if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst))
|
else if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst))
|
||||||
return BinaryOperator::create(BinOp->getOpcode(), NewPN, ConstantOp);
|
return BinaryOperator::create(BinOp->getOpcode(), PhiVal, ConstantOp);
|
||||||
else
|
else
|
||||||
return new ShiftInst(cast<ShiftInst>(FirstInst)->getOpcode(),
|
return new ShiftInst(cast<ShiftInst>(FirstInst)->getOpcode(),
|
||||||
NewPN, ConstantOp);
|
PhiVal, ConstantOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PHINode simplification
|
// PHINode simplification
|
||||||
|
Reference in New Issue
Block a user