]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/ssa: remove double negation with addition on riscv64
authorJoel Sing <joel@sing.id.au>
Sun, 23 Feb 2025 13:37:45 +0000 (00:37 +1100)
committerJoel Sing <joel@sing.id.au>
Sat, 15 Mar 2025 13:04:28 +0000 (06:04 -0700)
commit10d070668c24a3f1b3982c323ba1334437941dff
tree8c7807d16b5f12a1b0d7ca0973a354b34b89b9a0
parenta8f2e63f2f5b661418f1e386e443e48356e72c40
cmd/compile/internal/ssa: remove double negation with addition on riscv64

On riscv64, subtraction from a constant is typically implemented as an
ADDI with the negative constant, followed by a negation. However this can
lead to multiple NEG/ADDI/NEG sequences that can be optimised out.

For example, runtime.(*_panic).nextDefer currently contains:

   lbu     t0, 0(t0)
   addi    t0, t0, -8
   neg     t0, t0
   addi    t0, t0, -7
   neg     t0, t0

Which is now optimised to:

   lbu     t0, 0(t0)
   addi    t0, t0, -1

Change-Id: Idf5815e6db2e3705cc4a4811ca9130a064ae3d80
Reviewed-on: https://go-review.googlesource.com/c/go/+/652318
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Ryan <markdryan@rivosinc.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/_gen/RISCV64.rules
src/cmd/compile/internal/ssa/rewriteRISCV64.go
test/codegen/arithmetic.go