Make instcombine not remove Phi nodes when LCSSA is live.

llvm-svn: 29083
This commit is contained in:
Owen Anderson 2006-07-10 19:03:49 +00:00
parent 7ac78b99e6
commit a6968f83b2
1 changed files with 50 additions and 46 deletions

View File

@ -96,6 +96,7 @@ namespace {
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetData>(); AU.addRequired<TargetData>();
AU.addPreservedID(LCSSAID);
AU.setPreservesCFG(); AU.setPreservesCFG();
} }
@ -6251,12 +6252,14 @@ static bool DeadPHICycle(PHINode *PN, std::set<PHINode*> &PotentiallyDeadPHIs) {
// PHINode simplification // PHINode simplification
// //
Instruction *InstCombiner::visitPHINode(PHINode &PN) { Instruction *InstCombiner::visitPHINode(PHINode &PN) {
// If LCSSA is around, don't nuke PHIs.
if (!mustPreserveAnalysisID(LCSSAID)) {
if (Value *V = PN.hasConstantValue()) if (Value *V = PN.hasConstantValue())
return ReplaceInstUsesWith(PN, V); return ReplaceInstUsesWith(PN, V);
// If the only user of this instruction is a cast instruction, and all of the // If the only user of this instruction is a cast instruction, and all of
// incoming values are constants, change this PHI to merge together the casted //the incoming values are constants, change this PHI to merge together the
// constants. // casted constants.
if (PN.hasOneUse()) if (PN.hasOneUse())
if (CastInst *CI = dyn_cast<CastInst>(PN.use_back())) if (CastInst *CI = dyn_cast<CastInst>(PN.use_back()))
if (CI->getType() != PN.getType()) { // noop casts will be folded if (CI->getType() != PN.getType()) { // noop casts will be folded
@ -6290,9 +6293,9 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
if (Instruction *Result = FoldPHIArgOpIntoPHI(PN)) if (Instruction *Result = FoldPHIArgOpIntoPHI(PN))
return Result; return Result;
// If this is a trivial cycle in the PHI node graph, remove it. Basically, if // If this is a trivial cycle in the PHI node graph, remove it. Basically,
// this PHI only has a single use (a PHI), and if that PHI only has one use (a // if this PHI only has a single use (a PHI), and if that PHI only has one
// PHI)... break the cycle. // use (a PHI)... break the cycle.
if (PN.hasOneUse()) if (PN.hasOneUse())
if (PHINode *PU = dyn_cast<PHINode>(PN.use_back())) { if (PHINode *PU = dyn_cast<PHINode>(PN.use_back())) {
std::set<PHINode*> PotentiallyDeadPHIs; std::set<PHINode*> PotentiallyDeadPHIs;
@ -6300,6 +6303,7 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
if (DeadPHICycle(PU, PotentiallyDeadPHIs)) if (DeadPHICycle(PU, PotentiallyDeadPHIs))
return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType())); return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType()));
} }
}
return 0; return 0;
} }