summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MustExecute.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/MustExecute.cpp')
-rw-r--r--llvm/lib/Analysis/MustExecute.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp
index d8bc7fa19ae..7b1bb2037f3 100644
--- a/llvm/lib/Analysis/MustExecute.cpp
+++ b/llvm/lib/Analysis/MustExecute.cpp
@@ -70,6 +70,10 @@ static bool CanProveNotTakenFirstIteration(BasicBlock *ExitBlock,
auto *BI = dyn_cast<BranchInst>(CondExitBlock->getTerminator());
if (!BI || !BI->isConditional())
return false;
+ // If condition is constant and false leads to ExitBlock then we always
+ // execute the true branch.
+ if (auto *Cond = dyn_cast<ConstantInt>(BI->getCondition()))
+ return BI->getSuccessor(Cond->getZExtValue() ? 1 : 0) == ExitBlock;
auto *Cond = dyn_cast<CmpInst>(BI->getCondition());
if (!Cond)
return false;
OpenPOWER on IntegriCloud