From bd374b27cc33567b0a0522ee511fc1ea9f0bb1df Mon Sep 17 00:00:00 2001 From: Max Kazantsev Date: Tue, 22 Jan 2019 09:36:22 +0000 Subject: [NFC] Add detector for guards expressed as branch by widenable conditions This patch adds a function to detect guards expressed in explicit control flow form as branch by `and` with widenable condition intrinsic call: %wc = call i1 @llvm.experimental.widenable.condition() %guard_cond = and i1, %some_cond, %wc br i1 %guard_cond, label %guarded, label %deopt deopt: deoptimize() This form can be used as alternative to implicit control flow guard representation expressed by `experimental_guard` intrinsic. Differential Revision: https://reviews.llvm.org/D56074 Reviewed By: reames llvm-svn: 351791 --- llvm/lib/Analysis/GuardUtils.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'llvm/lib/Analysis/GuardUtils.cpp') 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()); } + +bool llvm::isGuardAsWidenableBranch(const User *U) { + using namespace llvm::PatternMatch; + const BranchInst *BI = dyn_cast(U); + + // We are looking for the following pattern: + // br i1 %cond & widenable_condition(), label %guarded, label %deopt + // deopt: + // + // deoptimize() + if (!BI || !BI->isConditional()) + return false; + + if (!match(BI->getCondition(), + m_And(m_Value(), + m_Intrinsic()))) + return false; + + const BasicBlock *DeoptBlock = BI->getSuccessor(1); + for (auto &Insn : *DeoptBlock) { + if (match(&Insn, m_Intrinsic())) + return true; + if (Insn.mayHaveSideEffects()) + return false; + } + return false; +} -- cgit v1.2.3