SCEVExpander: Don't crash when trying to merge two constant phis.

Just constant fold them so they can't cause any trouble. Fixes PR12627.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166286 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Benjamin Kramer
2012-10-19 16:37:30 +00:00
parent 34674fea97
commit 239fd44f7a
3 changed files with 38 additions and 1 deletions

View File

@@ -1618,6 +1618,17 @@ unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
PEnd = Phis.end(); PIter != PEnd; ++PIter) {
PHINode *Phi = *PIter;
// Fold constant phis. They may be congruent to other constant phis and
// would confuse the logic below that expects proper IVs.
if (Value *V = Phi->hasConstantValue()) {
Phi->replaceAllUsesWith(V);
DeadInsts.push_back(Phi);
++NumElim;
DEBUG_WITH_TYPE(DebugType, dbgs()
<< "INDVARS: Eliminated constant iv: " << *Phi << '\n');
continue;
}
if (!SE.isSCEVable(Phi->getType()))
continue;