Skip to content

Commit 2469e92

Browse files
mengzhuogopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Joel Sing <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Keith Randall <[email protected]>
1 parent aa83aee commit 2469e92

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/cmd/compile/internal/ssa/_gen/RISCV64.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,10 @@
782782
(SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> uint32(x))])
783783
(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)])
784784

785+
// Combine doubling via addition with shift.
786+
(SLLI <t> [c] (ADD x x)) && c < t.Size() * 8 - 1 => (SLLI <t> [c+1] x)
787+
(SLLI <t> [c] (ADD x x)) && c >= t.Size() * 8 - 1 => (MOVDconst [0])
788+
785789
// SLTI/SLTIU with constants.
786790
(SLTI [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))])
787791
(SLTIU [x] (MOVDconst [y])) => (MOVDconst [b2i(uint64(y) < uint64(x))])

src/cmd/compile/internal/ssa/rewriteRISCV64.go

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/codegen/shift.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,41 @@ func rshConst64x32(v int64) int64 {
122122
func lshConst32x1Add(x int32) int32 {
123123
// amd64:"SHLL\t[$]2"
124124
// loong64:"SLL\t[$]2"
125+
// riscv64:"SLLI\t[$]2"
125126
return (x + x) << 1
126127
}
127128

128129
func lshConst64x1Add(x int64) int64 {
129130
// amd64:"SHLQ\t[$]2"
130131
// loong64:"SLLV\t[$]2"
132+
// riscv64:"SLLI\t[$]2"
131133
return (x + x) << 1
132134
}
133135

134136
func lshConst32x2Add(x int32) int32 {
135137
// amd64:"SHLL\t[$]3"
136138
// loong64:"SLL\t[$]3"
139+
// riscv64:"SLLI\t[$]3"
137140
return (x + x) << 2
138141
}
139142

140143
func lshConst64x2Add(x int64) int64 {
141144
// amd64:"SHLQ\t[$]3"
142145
// loong64:"SLLV\t[$]3"
146+
// riscv64:"SLLI\t[$]3"
143147
return (x + x) << 2
144148
}
145149

150+
func lshConst32x31Add(x int32) int32 {
151+
// riscv64:-"SLLI","MOV\t[$]0"
152+
return (x + x) << 31
153+
}
154+
155+
func lshConst64x63Add(x int64) int64 {
156+
// riscv64:-"SLLI","MOV\t[$]0"
157+
return (x + x) << 63
158+
}
159+
146160
// ------------------ //
147161
// masked shifts //
148162
// ------------------ //

0 commit comments

Comments
 (0)