[llvm] 3b2256a - [test] Make bt_order_by_weight in switch.ll more robust
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 28 13:00:07 PDT 2020
Author: Arthur Eubanks
Date: 2020-10-28T12:56:23-07:00
New Revision: 3b2256a41b062ff5e9dcf52a99b945cadf2388d1
URL: https://github.com/llvm/llvm-project/commit/3b2256a41b062ff5e9dcf52a99b945cadf2388d1
DIFF: https://github.com/llvm/llvm-project/commit/3b2256a41b062ff5e9dcf52a99b945cadf2388d1.diff
LOG: [test] Make bt_order_by_weight in switch.ll more robust
Branch weights are not represented internally linearly with the value in
the IR. In its current state the test happened to pass, but the branch
weights for 0,3,6 and 2,5,8,9 were not actually equal.
$ opt -passes='print<branch-prob>'
shows that the sum of the branch probabilities going to bb0 and bb2 were not the same.
Printing analysis results of BPI for function 'bt_order_by_weight':
---- Branch Probabilities ----
edge entry -> bb0 probability is 0x00000003 / 0x80000000 = 0.00%
edge entry -> bb2 probability is 0x00000004 / 0x80000000 = 0.00%
with this change:
Printing analysis results of BPI for function 'bt_order_by_weight':
---- Branch Probabilities ----
edge entry -> bb0 probability is 0x00000004 / 0x80000000 = 0.00%
edge entry -> bb2 probability is 0x00000004 / 0x80000000 = 0.00%
Reviewed By: hans
Differential Revision: https://reviews.llvm.org/D90273
Added:
Modified:
llvm/test/CodeGen/X86/switch.ll
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/X86/switch.ll b/llvm/test/CodeGen/X86/switch.ll
index 68cead3ad4dc..348dc92a8f48 100644
--- a/llvm/test/CodeGen/X86/switch.ll
+++ b/llvm/test/CodeGen/X86/switch.ll
@@ -521,11 +521,10 @@ bb2: tail call void @g(i32 2) br label %return
return: ret void
; Cases 1,4,7 have a very large branch weight (which shouldn't overflow), so
-; their bit test should come first. 0,3,6 and 2,5,8,9 both have a weight of 12,
-; but the latter set has more cases, so should be tested for earlier.
-; The bit test on 0,3,6 is unnecessary as all cases cover the rage [0, 9].
-; The range check guarantees that cases other than 1,4,7 and 2,5,8,9 must be
-; in 0,3,6.
+; their bit test should come first. 0,3,6 and 2,5,8,9 both have a weight of 20,
+; but the latter set has more cases, so should be tested for earlier. The bit
+; test on 0,3,6 is unnecessary as all cases cover the range [0, 9]. The range
+; check guarantees that cases other than 1,4,7 and 2,5,8,9 must be in 0,3,6.
; CHECK-LABEL: bt_order_by_weight
; 146 = 2^1 + 2^4 + 2^7
@@ -543,11 +542,11 @@ return: ret void
; Default:
i32 1,
; Cases 0,3,6:
- i32 4, i32 4, i32 4,
+ i32 0, i32 0, i32 20,
; Cases 1,4,7:
i32 4294967295, i32 2, i32 4294967295,
; Cases 2,5,8,9:
- i32 3, i32 3, i32 3, i32 3}
+ i32 0, i32 0, i32 0, i32 20}
define void @order_by_weight_and_fallthrough(i32 %x) {
entry:
More information about the llvm-commits
mailing list