]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: use zero constants in comparisons where possible
authorMichael Munday <mike.munday@lowrisc.org>
Mon, 20 Sep 2021 20:39:39 +0000 (21:39 +0100)
committerMichael Munday <mike.munday@lowrisc.org>
Mon, 27 Feb 2023 21:38:30 +0000 (21:38 +0000)
commit85d54a7667c12ea2320f43b24129a68f020ac095
treed8eff459f6e1f9ccf2ca3e18f0ad97197289ebaa
parent0ff91e03dbb7ed169915b12793cbee9ca9798d4c
cmd/compile: use zero constants in comparisons where possible

Some integer comparisons with 1 and -1 can be rewritten as comparisons
with 0. For example, x < 1 is equivalent to x <= 0. This is an
advantageous transformation on riscv64 because comparisons with zero
do not require a constant to be loaded into a register. Other
architectures will likely benefit too and the transformation is
relatively benign on architectures that do not benefit.

Change-Id: I2ce9821dd7605a660eb71d76e83a61f9bae1bf25
Reviewed-on: https://go-review.googlesource.com/c/go/+/350831
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Munday <mike.munday@lowrisc.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go
test/codegen/compare_and_branch.go
test/prove.go