[PATCH] D30631: [BPI] Use metadata info before any other heuristics

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 5 20:28:00 PST 2017


skatkov created this revision.

Metadata potentially is more precise than any heuritics we use.
It makes sense to use first metadata info if it is avalialbe.


https://reviews.llvm.org/D30631

Files:
  lib/Analysis/BranchProbabilityInfo.cpp
  test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll


Index: test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
===================================================================
--- test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
+++ test/Analysis/BranchProbabilityInfo/deopt-intrinsic.ll
@@ -19,3 +19,22 @@
 exit:
   ret i32 %b
 }
+
+define i32 @test2(i32 %a, i32 %b) {
+; CHECK-LABEL: Printing analysis {{.*}} for function 'test2':
+entry:
+  %cond = icmp eq i32 %a, 42
+  br i1 %cond, label %exit, label %deopt, !prof !0
+
+; CHECK:  edge entry -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+; CHECK:  edge entry -> deopt probability is 0x00000000 / 0x80000000 = 0.00%
+
+deopt:
+  %rval = call i32(...) @llvm.experimental.deoptimize.i32() [ "deopt"() ]
+  ret i32 %rval
+
+exit:
+  ret i32 %b
+}
+
+!0 = !{!"branch_weights", i32 1, i32 0}
Index: lib/Analysis/BranchProbabilityInfo.cpp
===================================================================
--- lib/Analysis/BranchProbabilityInfo.cpp
+++ lib/Analysis/BranchProbabilityInfo.cpp
@@ -671,10 +671,10 @@
   // the successors of a block iteratively.
   for (auto BB : post_order(&F.getEntryBlock())) {
     DEBUG(dbgs() << "Computing probabilities for " << BB->getName() << "\n");
-    if (calcUnreachableHeuristics(BB))
-      continue;
     if (calcMetadataWeights(BB))
       continue;
+    if (calcUnreachableHeuristics(BB))
+      continue;
     if (calcColdCallHeuristics(BB))
       continue;
     if (calcLoopBranchHeuristics(BB, LI))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30631.90639.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170306/b3e2b170/attachment.bin>


More information about the llvm-commits mailing list