[llvm] [RISCV] Remove setJumpIsExpensive(). (PR #74647)
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 07:42:12 PST 2023
asb wrote:
@topperc how does this look for you on e.g. SPEC? Running it across the GCC torture suite it's a very common pattern to have a long sequence of `if (foo_expr) abort(); if (foo2_expr) abort(); ...` and there are a number of examples where you had a (perhaps longish) block of loads and ALU operations turned into a series of branches. The single BB version seems better if all branches are not taken (i.e. all bne are evaluated).
```
--- a/output_rv64imafdc_lp64d_O3/20120808-1.s
+++ b/output_rv64imafdc_lp64d_O3/20120808-1.s
@@ -63,33 +63,37 @@ main: # @main
j .LBB0_2
.LBB0_8: # %for.end
lbu a0, 8(sp)
- lbu a1, 9(sp)
- xori a0, a0, 255
- lbu a2, 10(sp)
- lbu a3, 11(sp)
- xori a1, a1, 253
- or a0, a0, a1
- xori a1, a2, 251
- xori a2, a3, 255
- lbu a3, 12(sp)
- lbu a4, 33(sp)
- or a1, a1, a2
- or a0, a0, a1
- xori a1, a3, 255
- xori a2, a4, 254
- or a1, a1, a2
- or a0, a0, a1
- bnez a0, .LBB0_11
-# %bb.9: # %lor.lhs.false34
+ li a1, 255
+ bne a0, a1, .LBB0_16
+# %bb.9: # %for.end
+ lbu a0, 9(sp)
+ li a1, 253
+ bne a0, a1, .LBB0_16
+# %bb.10: # %for.end
+ lbu a0, 10(sp)
+ li a1, 251
+ bne a0, a1, .LBB0_16
+# %bb.11: # %for.end
+ lbu a1, 11(sp)
+ li a0, 255
+ bne a1, a0, .LBB0_16
+# %bb.12: # %for.end
+ lbu a1, 12(sp)
+ bne a1, a0, .LBB0_16
+# %bb.13: # %for.end
+ lbu a0, 33(sp)
+ li a1, 254
+ bne a0, a1, .LBB0_16
+# %bb.14: # %lor.lhs.false34
lui a0, %hi(cp)
ld a0, %lo(cp)(a0)
lui a1, %hi(d+30)
addi a1, a1, %lo(d+30)
- bne a0, a1, .LBB0_11
-# %bb.10: # %if.end
+ bne a0, a1, .LBB0_16
+# %bb.15: # %if.end
li a0, 0
call exit
-.LBB0_11: # %if.then
+.LBB0_16: # %if.then
call abort
.Lfunc_end0:
```
But of course I wouldn't try to argue the torture suite inputs represent typical code, and of course the tradeoff is different if one of those branches may be taken.
Another example would be:
```
-- a/output_rv64imafdc_lp64d_O3/20000622-1.s
+++ b/output_rv64imafdc_lp64d_O3/20000622-1.s
@@ -8,15 +8,18 @@
foo: # @foo
.cfi_startproc
# %bb.0: # %entry
- xori a0, a0, 12
- xori a1, a1, 1
- or a0, a0, a1
- xori a1, a2, 11
- or a0, a0, a1
- bnez a0, .LBB0_2
-# %bb.1: # %if.end
+ li a3, 12
+ bne a0, a3, .LBB0_4
+# %bb.1: # %entry
+ li a0, 1
+ bne a1, a0, .LBB0_4
+# %bb.2: # %entry
+ li a0, 11
+ bne a2, a0, .LBB0_4
+# %bb.3: # %if.end
+ li a0, 0
ret
-.LBB0_2: # %if.then
+.LBB0_4: # %if.then
addi sp, sp, -16
.cfi_def_cfa_offset 16
sd ra, 8(sp) # 8-byte Folded Spill
@@ -44,13 +47,14 @@ bar: # @bar
baz: # @baz
.cfi_startproc
# %bb.0: # %entry
- xori a0, a2, 12
- xori a1, a1, 11
- or a0, a0, a1
- bnez a0, .LBB2_2
-# %bb.1: # %foo.exit
+ li a0, 11
+ bne a1, a0, .LBB2_3
+# %bb.1: # %entry
+ li a0, 12
+ bne a2, a0, .LBB2_3
+# %bb.2: # %foo.exit
ret
-.LBB2_2: # %if.then.i
+.LBB2_3: # %if.then.i
```
Which especially for the diff in the baz function makes me wonder if there's some other tunable somewhere that might control this.
https://github.com/llvm/llvm-project/pull/74647
More information about the llvm-commits
mailing list