This xform is handled by FoldOpIntoPhi in visitCastInst in a more elegant way.

llvm-svn: 31889
This commit is contained in:
Chris Lattner 2006-11-21 17:05:13 +00:00
parent 5b96cdebb0
commit ec45a4c88c
1 changed files with 1 additions and 30 deletions

View File

@ -7144,35 +7144,6 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
if (Value *V = PN.hasConstantValue())
return ReplaceInstUsesWith(PN, V);
// If the only user of this instruction is a cast instruction, and all of the
// incoming values are constants, change this PHI to merge together the casted
// constants.
if (PN.hasOneUse())
if (CastInst *CI = dyn_cast<CastInst>(PN.use_back()))
if (CI->getType() != PN.getType()) { // noop casts will be folded
bool AllConstant = true;
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i)
if (!isa<Constant>(PN.getIncomingValue(i))) {
AllConstant = false;
break;
}
if (AllConstant) {
// Make a new PHI with all casted values.
PHINode *New = new PHINode(CI->getType(), PN.getName(), &PN);
for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) {
Constant *OldArg = cast<Constant>(PN.getIncomingValue(i));
New->addIncoming(ConstantExpr::getCast(OldArg, New->getType()),
PN.getIncomingBlock(i));
}
// Update the cast instruction.
CI->setOperand(0, New);
WorkList.push_back(CI); // revisit the cast instruction to fold.
WorkList.push_back(New); // Make sure to revisit the new Phi
return &PN; // PN is now dead!
}
}
// If all PHI operands are the same operation, pull them through the PHI,
// reducing code size.
if (isa<Instruction>(PN.getIncomingValue(0)) &&