diff options
author | Joel Sing <joel@sing.id.au> | 2021-08-17 19:09:33 +1000 |
---|---|---|
committer | Joel Sing <joel@sing.id.au> | 2021-08-21 11:23:14 +0000 |
commit | 8fff20ffebadfea2c5c3dd58f7007246f3408495 (patch) | |
tree | 739f18cf244cbcd00e50d5aa8849e3be73117b89 /src/cmd/compile/internal/ssa/gen | |
parent | bcd146d398da2a873bb3f5a6e026c70b411a4486 (diff) | |
download | go-8fff20ffebadfea2c5c3dd58f7007246f3408495.tar.gz go-8fff20ffebadfea2c5c3dd58f7007246f3408495.zip |
cmd/compile: absorb NEG into branch when possible on riscv64
We can end up with this situation due to our equality tests being based on
'SEQZ (SUB x y)' - if x is a zero valued constant, 'SUB x y' can be converted
to 'NEG x'. When used with a branch the SEQZ can be absorbed, leading to
'BNEZ (NEG x)' where the NEG is redundant.
Removes around 1700 instructions from the go binary on riscv64.
Change-Id: I947a080d8bf7d2d6378ab114172e2342ce2c51db
Reviewed-on: https://go-review.googlesource.com/c/go/+/342850
Trust: Joel Sing <joel@sing.id.au>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/gen')
-rw-r--r-- | src/cmd/compile/internal/ssa/gen/RISCV64.rules | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/gen/RISCV64.rules b/src/cmd/compile/internal/ssa/gen/RISCV64.rules index 1414b2b34d..4eb48e3928 100644 --- a/src/cmd/compile/internal/ssa/gen/RISCV64.rules +++ b/src/cmd/compile/internal/ssa/gen/RISCV64.rules @@ -588,6 +588,10 @@ (BNEZ (SEQZ x) yes no) => (BEQZ x yes no) (BNEZ (SNEZ x) yes no) => (BNEZ x yes no) +// Absorb NEG into branch when possible. +(BEQZ x:(NEG y) yes no) && x.Uses == 1 => (BEQZ y yes no) +(BNEZ x:(NEG y) yes no) && x.Uses == 1 => (BNEZ y yes no) + // Convert BEQZ/BNEZ into more optimal branch conditions. (BEQZ (SUB x y) yes no) => (BEQ x y yes no) (BNEZ (SUB x y) yes no) => (BNE x y yes no) |