diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index baa737e..77d3fe3 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -753,10 +753,19 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { FalseSucc->removePredecessor(BI->getParent()); // Insert a new select instruction. - Value *NewRetVal = new SelectInst(BI->getCondition(), TrueValue, - FalseValue, "retval", BI); + Value *NewRetVal; + Value *BrCond = BI->getCondition(); + if (TrueValue != FalseValue) + NewRetVal = new SelectInst(BrCond, TrueValue, + FalseValue, "retval", BI); + else + NewRetVal = TrueValue; + new ReturnInst(NewRetVal, BI); BI->getParent()->getInstList().erase(BI); + if (BrCond->use_empty()) + if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond)) + BrCondI->getParent()->getInstList().erase(BrCondI); return true; } } |