diff options
| author | Meng Zhuo <mengzhuo@iscas.ac.cn> | 2025-09-11 17:21:02 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-15 17:31:56 -0700 |
| commit | 2469e92d8c49536617136f744c9767e14f6461d2 (patch) | |
| tree | 8c4e4429e2f8d8e7c74ced279c3c9a745046b7b1 /src | |
| parent | aa83aee7de1d69b207ab9669bb2b7dcdcbdf9383 (diff) | |
| download | go-2469e92d8c49536617136f744c9767e14f6461d2.tar.xz | |
cmd/compile: combine doubling with shift on riscv64
Change-Id: I4bee2770fedf97e35b5a5b9187a8ba3c41f9ec2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/702697
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Keith Randall <khr@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/ssa/_gen/RISCV64.rules | 4 | ||||
| -rw-r--r-- | src/cmd/compile/internal/ssa/rewriteRISCV64.go | 36 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules index e14de328ea..7059273eb2 100644 --- a/src/cmd/compile/internal/ssa/_gen/RISCV64.rules +++ b/src/cmd/compile/internal/ssa/_gen/RISCV64.rules @@ -782,6 +782,10 @@ (SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> uint32(x))]) (SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)]) +// Combine doubling via addition with shift. +(SLLI <t> [c] (ADD x x)) && c < t.Size() * 8 - 1 => (SLLI <t> [c+1] x) +(SLLI <t> [c] (ADD x x)) && c >= t.Size() * 8 - 1 => (MOVDconst [0]) + // SLTI/SLTIU with constants. (SLTI [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))]) (SLTIU [x] (MOVDconst [y])) => (MOVDconst [b2i(uint64(y) < uint64(x))]) diff --git a/src/cmd/compile/internal/ssa/rewriteRISCV64.go b/src/cmd/compile/internal/ssa/rewriteRISCV64.go index 5723327bc9..a7b4cf1bc4 100644 --- a/src/cmd/compile/internal/ssa/rewriteRISCV64.go +++ b/src/cmd/compile/internal/ssa/rewriteRISCV64.go @@ -7185,6 +7185,42 @@ func rewriteValueRISCV64_OpRISCV64SLLI(v *Value) bool { v.AuxInt = int64ToAuxInt(y << uint32(x)) return true } + // match: (SLLI <t> [c] (ADD x x)) + // cond: c < t.Size() * 8 - 1 + // result: (SLLI <t> [c+1] x) + for { + t := v.Type + c := auxIntToInt64(v.AuxInt) + if v_0.Op != OpRISCV64ADD { + break + } + x := v_0.Args[1] + if x != v_0.Args[0] || !(c < t.Size()*8-1) { + break + } + v.reset(OpRISCV64SLLI) + v.Type = t + v.AuxInt = int64ToAuxInt(c + 1) + v.AddArg(x) + return true + } + // match: (SLLI <t> [c] (ADD x x)) + // cond: c >= t.Size() * 8 - 1 + // result: (MOVDconst [0]) + for { + t := v.Type + c := auxIntToInt64(v.AuxInt) + if v_0.Op != OpRISCV64ADD { + break + } + x := v_0.Args[1] + if x != v_0.Args[0] || !(c >= t.Size()*8-1) { + break + } + v.reset(OpRISCV64MOVDconst) + v.AuxInt = int64ToAuxInt(0) + return true + } return false } func rewriteValueRISCV64_OpRISCV64SLLW(v *Value) bool { |
