cmd/compile: cast riscv64 rewrite shifts to unsigned int

This appeases Go 1.4, making it possible to bootstrap GOARCH=riscv64 with
a Go 1.4 compiler.

Fixes #52583

Change-Id: Ib13c2afeb095b2bb1464dcd7f1502574209bc7ab
Reviewed-on: https://go-review.googlesource.com/c/go/+/409974
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Joel Sing 2022-06-02 05:09:09 +10:00
parent d43ddc1f3f
commit 95547aee8c
2 changed files with 11 additions and 11 deletions

View File

@ -735,9 +735,9 @@
(NEGW (MOVDconst [x])) => (MOVDconst [int64(int32(-x))]) (NEGW (MOVDconst [x])) => (MOVDconst [int64(int32(-x))])
// Shift of a constant. // Shift of a constant.
(SLLI [x] (MOVDconst [y])) && is32Bit(y << x) => (MOVDconst [y << x]) (SLLI [x] (MOVDconst [y])) && is32Bit(y << uint32(x)) => (MOVDconst [y << uint32(x)])
(SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> x)]) (SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> uint32(x))])
(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> x]) (SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)])
// SLTI/SLTIU with constants. // SLTI/SLTIU with constants.
(SLTI [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))]) (SLTI [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))])

View File

@ -4843,19 +4843,19 @@ func rewriteValueRISCV64_OpRISCV64SLL(v *Value) bool {
func rewriteValueRISCV64_OpRISCV64SLLI(v *Value) bool { func rewriteValueRISCV64_OpRISCV64SLLI(v *Value) bool {
v_0 := v.Args[0] v_0 := v.Args[0]
// match: (SLLI [x] (MOVDconst [y])) // match: (SLLI [x] (MOVDconst [y]))
// cond: is32Bit(y << x) // cond: is32Bit(y << uint32(x))
// result: (MOVDconst [y << x]) // result: (MOVDconst [y << uint32(x)])
for { for {
x := auxIntToInt64(v.AuxInt) x := auxIntToInt64(v.AuxInt)
if v_0.Op != OpRISCV64MOVDconst { if v_0.Op != OpRISCV64MOVDconst {
break break
} }
y := auxIntToInt64(v_0.AuxInt) y := auxIntToInt64(v_0.AuxInt)
if !(is32Bit(y << x)) { if !(is32Bit(y << uint32(x))) {
break break
} }
v.reset(OpRISCV64MOVDconst) v.reset(OpRISCV64MOVDconst)
v.AuxInt = int64ToAuxInt(y << x) v.AuxInt = int64ToAuxInt(y << uint32(x))
return true return true
} }
return false return false
@ -4913,7 +4913,7 @@ func rewriteValueRISCV64_OpRISCV64SRA(v *Value) bool {
func rewriteValueRISCV64_OpRISCV64SRAI(v *Value) bool { func rewriteValueRISCV64_OpRISCV64SRAI(v *Value) bool {
v_0 := v.Args[0] v_0 := v.Args[0]
// match: (SRAI [x] (MOVDconst [y])) // match: (SRAI [x] (MOVDconst [y]))
// result: (MOVDconst [int64(y) >> x]) // result: (MOVDconst [int64(y) >> uint32(x)])
for { for {
x := auxIntToInt64(v.AuxInt) x := auxIntToInt64(v.AuxInt)
if v_0.Op != OpRISCV64MOVDconst { if v_0.Op != OpRISCV64MOVDconst {
@ -4921,7 +4921,7 @@ func rewriteValueRISCV64_OpRISCV64SRAI(v *Value) bool {
} }
y := auxIntToInt64(v_0.AuxInt) y := auxIntToInt64(v_0.AuxInt)
v.reset(OpRISCV64MOVDconst) v.reset(OpRISCV64MOVDconst)
v.AuxInt = int64ToAuxInt(int64(y) >> x) v.AuxInt = int64ToAuxInt(int64(y) >> uint32(x))
return true return true
} }
return false return false
@ -4947,7 +4947,7 @@ func rewriteValueRISCV64_OpRISCV64SRL(v *Value) bool {
func rewriteValueRISCV64_OpRISCV64SRLI(v *Value) bool { func rewriteValueRISCV64_OpRISCV64SRLI(v *Value) bool {
v_0 := v.Args[0] v_0 := v.Args[0]
// match: (SRLI [x] (MOVDconst [y])) // match: (SRLI [x] (MOVDconst [y]))
// result: (MOVDconst [int64(uint64(y) >> x)]) // result: (MOVDconst [int64(uint64(y) >> uint32(x))])
for { for {
x := auxIntToInt64(v.AuxInt) x := auxIntToInt64(v.AuxInt)
if v_0.Op != OpRISCV64MOVDconst { if v_0.Op != OpRISCV64MOVDconst {
@ -4955,7 +4955,7 @@ func rewriteValueRISCV64_OpRISCV64SRLI(v *Value) bool {
} }
y := auxIntToInt64(v_0.AuxInt) y := auxIntToInt64(v_0.AuxInt)
v.reset(OpRISCV64MOVDconst) v.reset(OpRISCV64MOVDconst)
v.AuxInt = int64ToAuxInt(int64(uint64(y) >> x)) v.AuxInt = int64ToAuxInt(int64(uint64(y) >> uint32(x)))
return true return true
} }
return false return false