]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: cast riscv64 rewrite shifts to unsigned int
authorJoel Sing <joel@sing.id.au>
Wed, 1 Jun 2022 19:09:09 +0000 (05:09 +1000)
committerJoel Sing <joel@sing.id.au>
Mon, 6 Jun 2022 19:03:15 +0000 (19:03 +0000)
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>
src/cmd/compile/internal/ssa/gen/RISCV64.rules
src/cmd/compile/internal/ssa/rewriteRISCV64.go

index 7aea622c5e81139212726c98f7c72db9ca9be3c3..dd20be2aeb9722f04c73712081bdc0c7258b9341 100644 (file)
 (NEGW (MOVDconst [x])) => (MOVDconst [int64(int32(-x))])
 
 // Shift of a constant.
-(SLLI [x] (MOVDconst [y])) && is32Bit(y << x) => (MOVDconst [y << x])
-(SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> x)])
-(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> x])
+(SLLI [x] (MOVDconst [y])) && is32Bit(y << uint32(x)) => (MOVDconst [y << uint32(x)])
+(SRLI [x] (MOVDconst [y])) => (MOVDconst [int64(uint64(y) >> uint32(x))])
+(SRAI [x] (MOVDconst [y])) => (MOVDconst [int64(y) >> uint32(x)])
 
 // SLTI/SLTIU with constants.
 (SLTI  [x] (MOVDconst [y])) => (MOVDconst [b2i(int64(y) < int64(x))])
index 6828d97ff8f7df0e26d9360b776110f5aeeb8c7b..2677e99dc028bcb1e68b6c61094c23d9f4e17450 100644 (file)
@@ -4843,19 +4843,19 @@ func rewriteValueRISCV64_OpRISCV64SLL(v *Value) bool {
 func rewriteValueRISCV64_OpRISCV64SLLI(v *Value) bool {
        v_0 := v.Args[0]
        // match: (SLLI [x] (MOVDconst [y]))
-       // cond: is32Bit(y << x)
-       // result: (MOVDconst [y << x])
+       // cond: is32Bit(y << uint32(x))
+       // result: (MOVDconst [y << uint32(x)])
        for {
                x := auxIntToInt64(v.AuxInt)
                if v_0.Op != OpRISCV64MOVDconst {
                        break
                }
                y := auxIntToInt64(v_0.AuxInt)
-               if !(is32Bit(y << x)) {
+               if !(is32Bit(y << uint32(x))) {
                        break
                }
                v.reset(OpRISCV64MOVDconst)
-               v.AuxInt = int64ToAuxInt(y << x)
+               v.AuxInt = int64ToAuxInt(y << uint32(x))
                return true
        }
        return false
@@ -4913,7 +4913,7 @@ func rewriteValueRISCV64_OpRISCV64SRA(v *Value) bool {
 func rewriteValueRISCV64_OpRISCV64SRAI(v *Value) bool {
        v_0 := v.Args[0]
        // match: (SRAI [x] (MOVDconst [y]))
-       // result: (MOVDconst [int64(y) >> x])
+       // result: (MOVDconst [int64(y) >> uint32(x)])
        for {
                x := auxIntToInt64(v.AuxInt)
                if v_0.Op != OpRISCV64MOVDconst {
@@ -4921,7 +4921,7 @@ func rewriteValueRISCV64_OpRISCV64SRAI(v *Value) bool {
                }
                y := auxIntToInt64(v_0.AuxInt)
                v.reset(OpRISCV64MOVDconst)
-               v.AuxInt = int64ToAuxInt(int64(y) >> x)
+               v.AuxInt = int64ToAuxInt(int64(y) >> uint32(x))
                return true
        }
        return false
@@ -4947,7 +4947,7 @@ func rewriteValueRISCV64_OpRISCV64SRL(v *Value) bool {
 func rewriteValueRISCV64_OpRISCV64SRLI(v *Value) bool {
        v_0 := v.Args[0]
        // match: (SRLI [x] (MOVDconst [y]))
-       // result: (MOVDconst [int64(uint64(y) >> x)])
+       // result: (MOVDconst [int64(uint64(y) >> uint32(x))])
        for {
                x := auxIntToInt64(v.AuxInt)
                if v_0.Op != OpRISCV64MOVDconst {
@@ -4955,7 +4955,7 @@ func rewriteValueRISCV64_OpRISCV64SRLI(v *Value) bool {
                }
                y := auxIntToInt64(v_0.AuxInt)
                v.reset(OpRISCV64MOVDconst)
-               v.AuxInt = int64ToAuxInt(int64(uint64(y) >> x))
+               v.AuxInt = int64ToAuxInt(int64(uint64(y) >> uint32(x)))
                return true
        }
        return false