diff options
author | Davide Italiano <davide@freebsd.org> | 2016-12-05 23:04:21 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2016-12-05 23:04:21 +0000 |
commit | 3dad93d9ef8a144d8928a8da130c790ffcd6c043 (patch) | |
tree | 1616429a926333561761b79f2ccc3634d03c6908 /llvm/lib/Transforms/Scalar/SCCP.cpp | |
parent | ebd5350d855d0c017f06b02ae95890ea30c45eea (diff) | |
download | bcm5719-llvm-3dad93d9ef8a144d8928a8da130c790ffcd6c043.tar.gz bcm5719-llvm-3dad93d9ef8a144d8928a8da130c790ffcd6c043.zip |
[SCCP] Remove manual folding of terminator instructions.
There are two cases handled here:
1) a branch on undef
2) a switch with an undef condition.
Both cases are currently handled by ResolvedUndefsIn. If we have
a branch on undef, we force its value to false (which is trivially
foldable). If we have a switch on undef, we force to the first
constant (which is also foldable).
llvm-svn: 288725
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SCCP.cpp | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index 32f486744f5..6f4a2ae92ff 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1828,33 +1828,8 @@ static bool runIPSCCP(Module &M, const DataLayout &DL, // Ignore blockaddress users; BasicBlock's dtor will handle them. if (!I) continue; - 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(); - } + assert(ConstantFoldTerminator(I->getParent()) && + "Terminator should've been folded"); } // Finally, delete the basic block. |