[PATCH] D56074: [NFC] Add detector function for explicitly expressed guards

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 01:36:35 PST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL351791: [NFC] Add detector for guards expressed as branch by widenable conditions (authored by mkazantsev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D56074?vs=179488&id=182861#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56074/new/

https://reviews.llvm.org/D56074

Files:
  llvm/trunk/include/llvm/Analysis/GuardUtils.h
  llvm/trunk/lib/Analysis/GuardUtils.cpp


Index: llvm/trunk/include/llvm/Analysis/GuardUtils.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/GuardUtils.h
+++ llvm/trunk/include/llvm/Analysis/GuardUtils.h
@@ -16,10 +16,14 @@
 
 class User;
 
-/// Returns true iff \p U has semantics of a guard.
+/// Returns true iff \p U has semantics of a guard expressed in a form of call
+/// of llvm.experimental.guard intrinsic.
 bool isGuard(const User *U);
 
+/// Returns true iff \p U has semantics of a guard expressed in a form of a
+/// widenable conditional branch to deopt block.
+bool isGuardAsWidenableBranch(const User *U);
+
 } // llvm
 
 #endif // LLVM_ANALYSIS_GUARDUTILS_H
-
Index: llvm/trunk/lib/Analysis/GuardUtils.cpp
===================================================================
--- llvm/trunk/lib/Analysis/GuardUtils.cpp
+++ llvm/trunk/lib/Analysis/GuardUtils.cpp
@@ -18,3 +18,30 @@
   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;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56074.182861.patch
Type: text/x-patch
Size: 1860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190122/4fccfa83/attachment.bin>


More information about the llvm-commits mailing list