summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2016-12-06 02:26:50 +0000
committerDavide Italiano <davide@freebsd.org>2016-12-06 02:26:50 +0000
commitdf670a19849c80142069fdf64d01c88ab06964a4 (patch)
treee8539ff2088fa62289e1424040a6804801eb6029 /llvm/lib/Transforms/Scalar/SCCP.cpp
parent639f84bd2d9ae45bb409efd0649e324ce4be3f64 (diff)
downloadbcm5719-llvm-df670a19849c80142069fdf64d01c88ab06964a4.tar.gz
bcm5719-llvm-df670a19849c80142069fdf64d01c88ab06964a4.zip
Revert "[SCCP] Remove manual folding of terminator instructions."
This reverts commit r288725 as it broke a bot. llvm-svn: 288759
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 6f4a2ae92ff..32f486744f5 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -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.
OpenPOWER on IntegriCloud