summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/GuardUtils.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/GuardUtils.cpp b/llvm/lib/Analysis/GuardUtils.cpp
index 2cee473e289..36ae954ed8b 100644
--- a/llvm/lib/Analysis/GuardUtils.cpp
+++ b/llvm/lib/Analysis/GuardUtils.cpp
@@ -18,3 +18,30 @@ bool llvm::isGuard(const User *U) {
using namespace llvm::PatternMatch;
return match(U, m_Intrinsic<Intrinsic::experimental_guard>());
}
+
+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())
+ 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) {
+ if (match(&Insn, m_Intrinsic<Intrinsic::experimental_deoptimize>()))
+ return true;
+ if (Insn.mayHaveSideEffects())
+ return false;
+ }
+ return false;
+}
OpenPOWER on IntegriCloud