mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-29 06:30:30 +00:00
Revert "[SCCP] Remove manual folding of terminator instructions."
This reverts commit r288725 as it broke a bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288759 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1af757cc00
commit
4b6e5ecd86
@ -1828,8 +1828,33 @@ static bool runIPSCCP(Module &M, const DataLayout &DL,
|
||||
// Ignore blockaddress users; BasicBlock's dtor will handle them.
|
||||
if (!I) continue;
|
||||
|
||||
assert(ConstantFoldTerminator(I->getParent()) &&
|
||||
"Terminator should've been folded");
|
||||
bool Folded = ConstantFoldTerminator(I->getParent());
|
||||
if (!Folded) {
|
||||
// The constant folder may not have been able to fold the terminator
|
||||
// if this is a branch or switch on undef. Fold it manually as a
|
||||
// branch to the first successor.
|
||||
#ifndef NDEBUG
|
||||
if (auto *BI = dyn_cast<BranchInst>(I)) {
|
||||
assert(BI->isConditional() && isa<UndefValue>(BI->getCondition()) &&
|
||||
"Branch should be foldable!");
|
||||
} else if (auto *SI = dyn_cast<SwitchInst>(I)) {
|
||||
assert(isa<UndefValue>(SI->getCondition()) && "Switch should fold");
|
||||
} else {
|
||||
llvm_unreachable("Didn't fold away reference to block!");
|
||||
}
|
||||
#endif
|
||||
|
||||
// Make this an uncond branch to the first successor.
|
||||
TerminatorInst *TI = I->getParent()->getTerminator();
|
||||
BranchInst::Create(TI->getSuccessor(0), TI);
|
||||
|
||||
// Remove entries in successor phi nodes to remove edges.
|
||||
for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i)
|
||||
TI->getSuccessor(i)->removePredecessor(TI->getParent());
|
||||
|
||||
// Remove the old terminator.
|
||||
TI->eraseFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, delete the basic block.
|
||||
|
Loading…
Reference in New Issue
Block a user