summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 1c27bc67cfb..4976893ad51 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2722,13 +2722,17 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI,
// If BI is reached from the true path of PBI and PBI's condition implies
// BI's condition, we know the direction of the BI branch.
+ bool ImpliedTrue;
if (PBI->getSuccessor(0) == BI->getParent() &&
- isImpliedCondition(PBI->getCondition(), BI->getCondition(), DL) &&
+ isImpliedCondition(PBI->getCondition(), BI->getCondition(), ImpliedTrue,
+ DL) &&
PBI->getSuccessor(0) != PBI->getSuccessor(1) &&
BB->getSinglePredecessor()) {
// Turn this into a branch on constant.
auto *OldCond = BI->getCondition();
- BI->setCondition(ConstantInt::getTrue(BB->getContext()));
+ ConstantInt *CI = ImpliedTrue ? ConstantInt::getTrue(BB->getContext())
+ : ConstantInt::getFalse(BB->getContext());
+ BI->setCondition(CI);
RecursivelyDeleteTriviallyDeadInstructions(OldCond);
return true; // Nuke the branch on constant.
}
OpenPOWER on IntegriCloud