aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp
index bbeb28d977..f4d02573cd 100644
--- a/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -521,8 +521,16 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
SwitchInst *NewSI = new SwitchInst(CV, PredDefault, PTI);
for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
NewSI->addCase(PredCases[i].first, PredCases[i].second);
+
+ Instruction *DeadCond = 0;
+ if (BranchInst *BI = dyn_cast<BranchInst>(PTI))
+ // If PTI is a branch, remember the condition.
+ DeadCond = dyn_cast<Instruction>(BI->getCondition());
Pred->getInstList().erase(PTI);
+ // If the condition is dead now, remove the instruction tree.
+ if (DeadCond) ErasePossiblyDeadInstructionTree(DeadCond);
+
// Okay, last check. If BB is still a successor of PSI, then we must
// have an infinite loop case. If so, add an infinitely looping block
// to handle the case to preserve the behavior of the code.