From a0e738c657d33e2a648838546812fb50cf42e41d Mon Sep 17 00:00:00 2001 From: Mark Ryan Date: Thu, 13 Nov 2025 12:28:29 +0100 Subject: 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 Reviewed-by: Junyang Shao LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall Reviewed-by: Joel Sing Auto-Submit: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/test/testdata/arith_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/cmd/compile/internal/test/testdata') diff --git a/src/cmd/compile/internal/test/testdata/arith_test.go b/src/cmd/compile/internal/test/testdata/arith_test.go index 8984cd3e26..34ac73c068 100644 --- a/src/cmd/compile/internal/test/testdata/arith_test.go +++ b/src/cmd/compile/internal/test/testdata/arith_test.go @@ -444,6 +444,19 @@ func testBitwiseRshU_ssa(a uint32, b, c uint32) uint32 { return a >> b >> c } +//go:noinline +func orLt_ssa(x int) bool { + y := x - x + return (x | 2) < y +} + +// test riscv64 SLTI rules +func testSetIfLessThan(t *testing.T) { + if want, got := true, orLt_ssa(-7); got != want { + t.Errorf("orLt_ssa(-7) = %t want %t", got, want) + } +} + //go:noinline func testShiftCX_ssa() int { v1 := uint8(3) @@ -977,6 +990,7 @@ func TestArithmetic(t *testing.T) { testRegallocCVSpill(t) testSubqToNegq(t) testBitwiseLogic(t) + testSetIfLessThan(t) testOcom(t) testLrot(t) testShiftCX(t) -- cgit v1.3-5-g45d5