llvm.org GIT mirror llvm / d926422
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267615 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 years ago
2 changed file(s) with 22 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
3333 STATISTIC(ExpectIntrinsicsHandled,
3434 "Number of 'expect' intrinsic instructions handled");
3535
36 static cl::opt
37 LikelyBranchWeight("likely-branch-weight", cl::Hidden, cl::init(64),
38 cl::desc("Weight of the branch likely to be taken (default = 64)"));
39 static cl::opt
40 UnlikelyBranchWeight("unlikely-branch-weight", cl::Hidden, cl::init(4),
41 cl::desc("Weight of the branch unlikely to be taken (default = 4)"));
36 // These default values are chosen to represent an extremely skewed outcome for
37 // a condition, but they leave some room for interpretation by later passes.
38 //
39 // If the documentation for __builtin_expect() was made explicit that it should
40 // only be used in extreme cases, we could make this ratio higher. As it stands,
41 // programmers may be using __builtin_expect() / llvm.expect to annotate that a
42 // branch is likely or unlikely to be taken.
43 //
44 // There is a known dependency on this ratio in CodeGenPrepare when transforming
45 // 'select' instructions. It may be worthwhile to hoist these values to some
46 // shared space, so they can be used directly by other passes.
47
48 static cl::opt LikelyBranchWeight(
49 "likely-branch-weight", cl::Hidden, cl::init(2000),
50 cl::desc("Weight of the branch likely to be taken (default = 2000)"));
51 static cl::opt UnlikelyBranchWeight(
52 "unlikely-branch-weight", cl::Hidden, cl::init(1),
53 cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
4254
4355 static bool handleSwitchExpect(SwitchInst &SI) {
4456 CallInst *CI = dyn_cast(SI.getCondition());
274274
275275 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
276276
277 ; CHECK: !0 = !{!"branch_weights", i32 64, i32 4}
278 ; CHECK: !1 = !{!"branch_weights", i32 4, i32 64}
279 ; CHECK: !2 = !{!"branch_weights", i32 4, i32 64, i32 4}
280 ; CHECK: !3 = !{!"branch_weights", i32 64, i32 4, i32 4}
277 ; CHECK: !0 = !{!"branch_weights", i32 2000, i32 1}
278 ; CHECK: !1 = !{!"branch_weights", i32 1, i32 2000}
279 ; CHECK: !2 = !{!"branch_weights", i32 1, i32 2000, i32 1}
280 ; CHECK: !3 = !{!"branch_weights", i32 2000, i32 1, i32 1}