]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: stop MOVW-ing -1 as SRA shift amount in mips
authorAlberto Donizetti <alb.donizetti@gmail.com>
Tue, 17 Nov 2020 09:13:29 +0000 (10:13 +0100)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Wed, 18 Nov 2020 12:04:06 +0000 (12:04 +0000)
The shift amount in SRAconst needs to be in the [0,31] range, so stop
MOVWing -1 to SRA in the Rsh lowering rules.

Also see CL 270117.

Passes

  $ GOARCH=mips go build -toolexec 'toolstash -cmp' -a std
  $ GOARCH=mipsle go build -toolexec 'toolstash -cmp' -a std

Updates #42587

Change-Id: Ib5eb99b82310e404cc2d6f0c619b21b8a15406ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/270558
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alberto Donizetti <alb.donizetti@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/compile/internal/ssa/gen/MIPS.rules
src/cmd/compile/internal/ssa/rewriteMIPS.go

index 7dcac9cf5391ac5210dd2ad8cdcad20a38d09608..470cc668694fa46e670a07a1ad956ce38be8f239 100644 (file)
 (Rsh8Ux16 <t> x y) => (CMOVZ (SRL <t> (ZeroExt8to32 x) (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y)))
 (Rsh8Ux8 <t> x y)  => (CMOVZ (SRL <t> (ZeroExt8to32 x) (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y)))
 
-(Rsh32x32 x y) => (SRA x ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
-(Rsh32x16 x y) => (SRA x ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
-(Rsh32x8 x y)  => (SRA x ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+(Rsh32x32 x y) => (SRA x ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
+(Rsh32x16 x y) => (SRA x ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
+(Rsh32x8 x y)  => (SRA x ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
 
-(Rsh16x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
-(Rsh16x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
-(Rsh16x8 x y)  => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+(Rsh16x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
+(Rsh16x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
+(Rsh16x8 x y)  => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
 
-(Rsh8x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
-(Rsh8x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
-(Rsh8x8 x y)  => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+(Rsh8x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
+(Rsh8x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
+(Rsh8x8 x y)  => (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
 
 // rotates
 (RotateLeft8  <t> x (MOVWconst [c])) => (Or8  (Lsh8x32 <t>  x (MOVWconst [c&7]))  (Rsh8Ux32 <t> x (MOVWconst [-c&7])))
index cfe39d7842c0487d1d8cf79618da1437fe791b8b..bbc331014fed77cb4d973f2c47a782603189ec91 100644 (file)
@@ -5697,7 +5697,7 @@ func rewriteValueMIPS_OpRsh16x16(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh16x16 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
        for {
                x := v_0
                y := v_1
@@ -5708,7 +5708,7 @@ func rewriteValueMIPS_OpRsh16x16(v *Value) bool {
                v2 := b.NewValue0(v.Pos, OpZeroExt16to32, typ.UInt32)
                v2.AddArg(y)
                v3 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v3.AuxInt = int32ToAuxInt(-1)
+               v3.AuxInt = int32ToAuxInt(31)
                v4 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v4.AuxInt = int32ToAuxInt(32)
                v4.AddArg(v2)
@@ -5723,7 +5723,7 @@ func rewriteValueMIPS_OpRsh16x32(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh16x32 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
        for {
                x := v_0
                y := v_1
@@ -5732,7 +5732,7 @@ func rewriteValueMIPS_OpRsh16x32(v *Value) bool {
                v0.AddArg(x)
                v1 := b.NewValue0(v.Pos, OpMIPSCMOVZ, typ.UInt32)
                v2 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v2.AuxInt = int32ToAuxInt(-1)
+               v2.AuxInt = int32ToAuxInt(31)
                v3 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v3.AuxInt = int32ToAuxInt(32)
                v3.AddArg(y)
@@ -5794,7 +5794,7 @@ func rewriteValueMIPS_OpRsh16x8(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh16x8 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
        for {
                x := v_0
                y := v_1
@@ -5805,7 +5805,7 @@ func rewriteValueMIPS_OpRsh16x8(v *Value) bool {
                v2 := b.NewValue0(v.Pos, OpZeroExt8to32, typ.UInt32)
                v2.AddArg(y)
                v3 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v3.AuxInt = int32ToAuxInt(-1)
+               v3.AuxInt = int32ToAuxInt(31)
                v4 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v4.AuxInt = int32ToAuxInt(32)
                v4.AddArg(v2)
@@ -5930,7 +5930,7 @@ func rewriteValueMIPS_OpRsh32x16(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh32x16 x y)
-       // result: (SRA x ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
+       // result: (SRA x ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
        for {
                x := v_0
                y := v_1
@@ -5939,7 +5939,7 @@ func rewriteValueMIPS_OpRsh32x16(v *Value) bool {
                v1 := b.NewValue0(v.Pos, OpZeroExt16to32, typ.UInt32)
                v1.AddArg(y)
                v2 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v2.AuxInt = int32ToAuxInt(-1)
+               v2.AuxInt = int32ToAuxInt(31)
                v3 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v3.AuxInt = int32ToAuxInt(32)
                v3.AddArg(v1)
@@ -5954,14 +5954,14 @@ func rewriteValueMIPS_OpRsh32x32(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh32x32 x y)
-       // result: (SRA x ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
+       // result: (SRA x ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
        for {
                x := v_0
                y := v_1
                v.reset(OpMIPSSRA)
                v0 := b.NewValue0(v.Pos, OpMIPSCMOVZ, typ.UInt32)
                v1 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v1.AuxInt = int32ToAuxInt(-1)
+               v1.AuxInt = int32ToAuxInt(31)
                v2 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v2.AuxInt = int32ToAuxInt(32)
                v2.AddArg(y)
@@ -6015,7 +6015,7 @@ func rewriteValueMIPS_OpRsh32x8(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh32x8 x y)
-       // result: (SRA x ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+       // result: (SRA x ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
        for {
                x := v_0
                y := v_1
@@ -6024,7 +6024,7 @@ func rewriteValueMIPS_OpRsh32x8(v *Value) bool {
                v1 := b.NewValue0(v.Pos, OpZeroExt8to32, typ.UInt32)
                v1.AddArg(y)
                v2 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v2.AuxInt = int32ToAuxInt(-1)
+               v2.AuxInt = int32ToAuxInt(31)
                v3 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v3.AuxInt = int32ToAuxInt(32)
                v3.AddArg(v1)
@@ -6160,7 +6160,7 @@ func rewriteValueMIPS_OpRsh8x16(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh8x16 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y))))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y))))
        for {
                x := v_0
                y := v_1
@@ -6171,7 +6171,7 @@ func rewriteValueMIPS_OpRsh8x16(v *Value) bool {
                v2 := b.NewValue0(v.Pos, OpZeroExt16to32, typ.UInt32)
                v2.AddArg(y)
                v3 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v3.AuxInt = int32ToAuxInt(-1)
+               v3.AuxInt = int32ToAuxInt(31)
                v4 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v4.AuxInt = int32ToAuxInt(32)
                v4.AddArg(v2)
@@ -6186,7 +6186,7 @@ func rewriteValueMIPS_OpRsh8x32(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh8x32 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [-1]) (SGTUconst [32] y)))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> y (MOVWconst [31]) (SGTUconst [32] y)))
        for {
                x := v_0
                y := v_1
@@ -6195,7 +6195,7 @@ func rewriteValueMIPS_OpRsh8x32(v *Value) bool {
                v0.AddArg(x)
                v1 := b.NewValue0(v.Pos, OpMIPSCMOVZ, typ.UInt32)
                v2 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v2.AuxInt = int32ToAuxInt(-1)
+               v2.AuxInt = int32ToAuxInt(31)
                v3 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v3.AuxInt = int32ToAuxInt(32)
                v3.AddArg(y)
@@ -6257,7 +6257,7 @@ func rewriteValueMIPS_OpRsh8x8(v *Value) bool {
        b := v.Block
        typ := &b.Func.Config.Types
        // match: (Rsh8x8 x y)
-       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y))))
+       // result: (SRA (SignExt16to32 x) ( CMOVZ <typ.UInt32> (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y))))
        for {
                x := v_0
                y := v_1
@@ -6268,7 +6268,7 @@ func rewriteValueMIPS_OpRsh8x8(v *Value) bool {
                v2 := b.NewValue0(v.Pos, OpZeroExt8to32, typ.UInt32)
                v2.AddArg(y)
                v3 := b.NewValue0(v.Pos, OpMIPSMOVWconst, typ.UInt32)
-               v3.AuxInt = int32ToAuxInt(-1)
+               v3.AuxInt = int32ToAuxInt(31)
                v4 := b.NewValue0(v.Pos, OpMIPSSGTUconst, typ.Bool)
                v4.AuxInt = int32ToAuxInt(32)
                v4.AddArg(v2)