From d2d2aa52cda3ea9d68bdd2052143ec67bdfd0c33 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 26 Apr 2016 22:23:38 +0000 Subject: [PATCH] [LowerExpectIntrinsic] make default likely/unlikely ratio bigger We need the default ratio to be sufficiently large that it triggers transforms based on block frequency info (BFI) and plays well with the recently introduced BranchProbability used by CGP. Differential Revision: http://reviews.llvm.org/D19435 llvm-svn: 267615 --- .../Scalar/LowerExpectIntrinsic.cpp | 24 ++++++++++++++----- .../Transforms/LowerExpectIntrinsic/basic.ll | 8 +++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp index 2ace902a7a1b..40ba74473590 100644 --- a/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp +++ b/llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp @@ -34,12 +34,24 @@ using namespace llvm; STATISTIC(ExpectIntrinsicsHandled, "Number of 'expect' intrinsic instructions handled"); -static cl::opt -LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(64), - cl::desc("Weight of the branch likely to be taken (default = 64)")); -static cl::opt -UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(4), - cl::desc("Weight of the branch unlikely to be taken (default = 4)")); +// These default values are chosen to represent an extremely skewed outcome for +// a condition, but they leave some room for interpretation by later passes. +// +// If the documentation for __builtin_expect() was made explicit that it should +// only be used in extreme cases, we could make this ratio higher. As it stands, +// programmers may be using __builtin_expect() / llvm.expect to annotate that a +// branch is likely or unlikely to be taken. +// +// There is a known dependency on this ratio in CodeGenPrepare when transforming +// 'select' instructions. It may be worthwhile to hoist these values to some +// shared space, so they can be used directly by other passes. + +static cl::opt LikelyBranchWeight( + "likely-branch-weight", cl::Hidden, cl::init(2000), + cl::desc("Weight of the branch likely to be taken (default = 2000)")); +static cl::opt UnlikelyBranchWeight( + "unlikely-branch-weight", cl::Hidden, cl::init(1), + cl::desc("Weight of the branch unlikely to be taken (default = 1)")); static bool handleSwitchExpect(SwitchInst &SI) { CallInst *CI = dyn_cast(SI.getCondition()); diff --git a/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll b/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll index 69e67cd7c1dd..562db86cefde 100644 --- a/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll +++ b/llvm/test/Transforms/LowerExpectIntrinsic/basic.ll @@ -275,7 +275,7 @@ return: ; preds = %if.end, %if.then 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 2000, i32 1} +; CHECK: !1 = !{!"branch_weights", i32 1, i32 2000} +; CHECK: !2 = !{!"branch_weights", i32 1, i32 2000, i32 1} +; CHECK: !3 = !{!"branch_weights", i32 2000, i32 1, i32 1}