[llvm] r266654 - [BPI] Consider deoptimize calls as "unreachable"

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 12:01:28 PDT 2016


Author: sanjoy
Date: Mon Apr 18 14:01:28 2016
New Revision: 266654

URL: http://llvm.org/viewvc/llvm-project?rev=266654&view=rev
Log:
[BPI] Consider deoptimize calls as "unreachable"

Summary:
Calls to @llvm.experimental.deoptimize are expected to "never execute",
so optimize them as such.

Reviewers: chandlerc

Subscribers: junbuml, mcrosier, llvm-commits

Differential Revision: http://reviews.llvm.org/D19095

Added:
    llvm/trunk/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
Modified:
    llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp

Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=266654&r1=266653&r2=266654&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Mon Apr 18 14:01:28 2016
@@ -115,7 +115,12 @@ static const uint32_t IH_NONTAKEN_WEIGHT
 bool BranchProbabilityInfo::calcUnreachableHeuristics(const BasicBlock *BB) {
   const TerminatorInst *TI = BB->getTerminator();
   if (TI->getNumSuccessors() == 0) {
-    if (isa<UnreachableInst>(TI))
+    if (isa<UnreachableInst>(TI) ||
+        // If this block is terminated by a call to
+        // @llvm.experimental.deoptimize then treat it like an unreachable since
+        // the @llvm.experimental.deoptimize call is expected to practically
+        // never execute.
+        BB->getTerminatingDeoptimizeCall())
       PostDominatedByUnreachable.insert(BB);
     return false;
   }

Added: llvm/trunk/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll?rev=266654&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll (added)
+++ llvm/trunk/test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll Mon Apr 18 14:01:28 2016
@@ -0,0 +1,20 @@
+; RUN: opt -analyze -branch-prob < %s | FileCheck %s
+
+declare i32 @llvm.experimental.deoptimize.i32(...)
+
+define i32 @test1(i32 %a, i32 %b) {
+; CHECK-LABEL: Printing analysis 'Branch Probability Analysis' for function 'test1':
+entry:
+  %cond = icmp eq i32 %a, 42
+  br i1 %cond, label %exit, label %deopt
+
+; CHECK:  edge entry -> exit probability is 0x7ffff800 / 0x80000000 = 100.00% [HOT edge]
+; CHECK:  edge entry -> deopt probability is 0x00000800 / 0x80000000 = 0.00%
+
+deopt:
+  %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"() ]
+  ret i32 %rval
+
+exit:
+  ret i32 %b
+}




More information about the llvm-commits mailing list