summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/GuardUtils.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/GuardUtils.cpp b/llvm/lib/Analysis/GuardUtils.cpp
index 36ae954ed8b..c099ee8e41c 100644
--- a/llvm/lib/Analysis/GuardUtils.cpp
+++ b/llvm/lib/Analysis/GuardUtils.cpp
@@ -20,24 +20,13 @@ bool llvm::isGuard(const User *U) {
}
bool llvm::isGuardAsWidenableBranch(const User *U) {
- using namespace llvm::PatternMatch;
- const BranchInst *BI = dyn_cast<BranchInst>(U);
-
- // We are looking for the following pattern:
- // br i1 %cond & widenable_condition(), label %guarded, label %deopt
- // deopt:
- // <non-side-effecting instructions>
- // deoptimize()
- if (!BI || !BI->isConditional())
+ Value *Condition, *WidenableCondition;
+ BasicBlock *GuardedBB, *DeoptBB;
+ if (!parseWidenableBranch(U, Condition, WidenableCondition, GuardedBB,
+ DeoptBB))
return false;
-
- if (!match(BI->getCondition(),
- m_And(m_Value(),
- m_Intrinsic<Intrinsic::experimental_widenable_condition>())))
- return false;
-
- const BasicBlock *DeoptBlock = BI->getSuccessor(1);
- for (auto &Insn : *DeoptBlock) {
+ using namespace llvm::PatternMatch;
+ for (auto &Insn : *DeoptBB) {
if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
return true;
if (Insn.mayHaveSideEffects())
@@ -45,3 +34,11 @@ bool llvm::isGuardAsWidenableBranch(const User *U) {
}
return false;
}
+
+bool llvm::parseWidenableBranch(const User *U, Value *&Condition,
+ Value *&WidenableCondition,
+ BasicBlock *&IfTrueBB, BasicBlock *&IfFalseBB) {
+ using namespace llvm::PatternMatch;
+ return match(U, m_Br(m_And(m_Value(Condition), m_Value(WidenableCondition)),
+ IfTrueBB, IfFalseBB));
+}
OpenPOWER on IntegriCloud