]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal: remove incorrect riscv64 SLTI rule
authorMark Ryan <markdryan@rivosinc.com>
Thu, 13 Nov 2025 11:28:29 +0000 (12:28 +0100)
committerGopher Robot <gobot@golang.org>
Fri, 14 Nov 2025 19:01:26 +0000 (11:01 -0800)
commita0e738c657d33e2a648838546812fb50cf42e41d
tree11e98e584095a39f897723b2386960a4be9a7742
parent2cdcc4150bc577e0b40a9cedaaa7c8301f2860cd
cmd/compile/internal: remove incorrect riscv64 SLTI rule

The rule

(SLTI  [x] (ORI  [y] _)) && y >= 0 && int64(y) >= int64(x) => (MOVDconst [0])

is incorrect as it only generates correct code if the unknown value
being compared is >= 0. If the unknown value is < 0 the rule will
incorrectly produce a constant value of 0, whereas the code optimized
away by the rule would have produced a value of 1.

A new test that causes the faulty rule to generate incorrect code
is also added to ensure that the error does not return.

Change-Id: I69224e0776596f1b9538acf9dacf9009d305f966
Reviewed-on: https://go-review.googlesource.com/c/go/+/720220
Reviewed-by: Meng Zhuo <mengzhuo1203@gmail.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/_gen/RISCV64.rules
src/cmd/compile/internal/ssa/rewriteRISCV64.go
src/cmd/compile/internal/test/testdata/arith_test.go