[PATCH] D19435: [LowerExpectIntrinsic] pin default likely/unlikely weights to min/max values

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 22 14:15:53 PDT 2016


spatel created this revision.
spatel added reviewers: davidxl, hfinkel, deadalnix.
spatel added a subscriber: llvm-commits.
Herald added a subscriber: mcrosier.

Given that D19300 (which would have deleted this file completely) has hit a potential roadblock, let's fix these default branch weights. I'm hoping to make progress on PR27344 without waiting for a conclusion to the debate about llvm.expect.

When a programmer uses __builtin_expect(), they are sending a strong message to the compiler: do everything you can to make the expected path optimal. The translation of that command to branch weights is that the likely path has the highest possible weight and the unlikely path has the lowest possible weight.

http://reviews.llvm.org/D19435

Files:
  lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
  test/Transforms/LowerExpectIntrinsic/basic.ll

Index: test/Transforms/LowerExpectIntrinsic/basic.ll
===================================================================
--- test/Transforms/LowerExpectIntrinsic/basic.ll
+++ test/Transforms/LowerExpectIntrinsic/basic.ll
@@ -275,7 +275,7 @@
 
 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
 
-; CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
-; CHECK: !1 = !{!"branch_weights", i32 4, i32 64}
-; CHECK: !2 = !{!"branch_weights", i32 4, i32 64, i32 4}
-; CHECK: !3 = !{!"branch_weights", i32 64, i32 4, i32 4}
+; CHECK: !0 = !{!"branch_weights", i32 -1, i32 0}
+; CHECK: !1 = !{!"branch_weights", i32 0, i32 -1}
+; CHECK: !2 = !{!"branch_weights", i32 0, i32 -1, i32 0}
+; CHECK: !3 = !{!"branch_weights", i32 -1, i32 0, i32 0}
Index: lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
===================================================================
--- lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -34,12 +34,12 @@
 STATISTIC(ExpectIntrinsicsHandled,
           "Number of 'expect' intrinsic instructions handled");
 
-static cl::opt<uint32_t>
-LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(64),
-                   cl::desc("Weight of the branch likely to be taken (default = 64)"));
-static cl::opt<uint32_t>
-UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(4),
-                   cl::desc("Weight of the branch unlikely to be taken (default = 4)"));
+static cl::opt<uint32_t> LikelyBranchWeight(
+    "likely-branch-weight", cl::Hidden, cl::init(4294967295),
+    cl::desc("Weight of the branch likely to be taken (default = 4294967295)"));
+static cl::opt<uint32_t> UnlikelyBranchWeight(
+    "unlikely-branch-weight", cl::Hidden, cl::init(0),
+    cl::desc("Weight of the branch unlikely to be taken (default = 0)"));
 
 static bool handleSwitchExpect(SwitchInst &SI) {
   CallInst *CI = dyn_cast<CallInst>(SI.getCondition());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19435.54719.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160422/3d091c75/attachment.bin>


More information about the llvm-commits mailing list