From 13b2f764c041e15af3d6033826deb9c7e669ca97 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 1 Jan 2005 16:02:12 +0000 Subject: [PATCH] Implement SimplifyCFG/DeadSetCC.ll SimplifyCFG is one of those passes that we use for final cleanup: it should not rely on other passes to clean up its garbage. This fixes the "why are trivially dead setcc's in the output of gccas" problem. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19212 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyCFG.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index bbeb28d9772..f4d02573cdc 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(PTI)) + // If PTI is a branch, remember the condition. + DeadCond = dyn_cast(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. -- 2.34.1