From 399b5d14d4114b326096127df9a89342eb1fc2ad Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 17 Nov 2020 10:13:29 +0100 Subject: [PATCH] cmd/compile: stop MOVW-ing -1 as SRA shift amount in mips 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 Run-TryBot: Alberto Donizetti TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/MIPS.rules | 18 +++++------ src/cmd/compile/internal/ssa/rewriteMIPS.go | 36 ++++++++++----------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/MIPS.rules b/src/cmd/compile/internal/ssa/gen/MIPS.rules index 7dcac9cf53..470cc66869 100644 --- a/src/cmd/compile/internal/ssa/gen/MIPS.rules +++ b/src/cmd/compile/internal/ssa/gen/MIPS.rules @@ -96,17 +96,17 @@ (Rsh8Ux16 x y) => (CMOVZ (SRL (ZeroExt8to32 x) (ZeroExt16to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt16to32 y))) (Rsh8Ux8 x y) => (CMOVZ (SRL (ZeroExt8to32 x) (ZeroExt8to32 y) ) (MOVWconst [0]) (SGTUconst [32] (ZeroExt8to32 y))) -(Rsh32x32 x y) => (SRA x ( CMOVZ y (MOVWconst [-1]) (SGTUconst [32] y))) -(Rsh32x16 x y) => (SRA x ( CMOVZ (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) -(Rsh32x8 x y) => (SRA x ( CMOVZ (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) +(Rsh32x32 x y) => (SRA x ( CMOVZ y (MOVWconst [31]) (SGTUconst [32] y))) +(Rsh32x16 x y) => (SRA x ( CMOVZ (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y)))) +(Rsh32x8 x y) => (SRA x ( CMOVZ (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y)))) -(Rsh16x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ y (MOVWconst [-1]) (SGTUconst [32] y))) -(Rsh16x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) -(Rsh16x8 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) +(Rsh16x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ y (MOVWconst [31]) (SGTUconst [32] y))) +(Rsh16x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y)))) +(Rsh16x8 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y)))) -(Rsh8x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ y (MOVWconst [-1]) (SGTUconst [32] y))) -(Rsh8x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) -(Rsh8x8 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) +(Rsh8x32 x y) => (SRA (SignExt16to32 x) ( CMOVZ y (MOVWconst [31]) (SGTUconst [32] y))) +(Rsh8x16 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt16to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt16to32 y)))) +(Rsh8x8 x y) => (SRA (SignExt16to32 x) ( CMOVZ (ZeroExt8to32 y) (MOVWconst [31]) (SGTUconst [32] (ZeroExt8to32 y)))) // rotates (RotateLeft8 x (MOVWconst [c])) => (Or8 (Lsh8x32 x (MOVWconst [c&7])) (Rsh8Ux32 x (MOVWconst [-c&7]))) diff --git a/src/cmd/compile/internal/ssa/rewriteMIPS.go b/src/cmd/compile/internal/ssa/rewriteMIPS.go index cfe39d7842..bbc331014f 100644 --- a/src/cmd/compile/internal/ssa/rewriteMIPS.go +++ b/src/cmd/compile/internal/ssa/rewriteMIPS.go @@ -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 (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) + // result: (SRA (SignExt16to32 x) ( CMOVZ (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 y (MOVWconst [-1]) (SGTUconst [32] y))) + // result: (SRA (SignExt16to32 x) ( CMOVZ 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 (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) + // result: (SRA (SignExt16to32 x) ( CMOVZ (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 (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) + // result: (SRA x ( CMOVZ (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 y (MOVWconst [-1]) (SGTUconst [32] y))) + // result: (SRA x ( CMOVZ 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 (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) + // result: (SRA x ( CMOVZ (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 (ZeroExt16to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt16to32 y)))) + // result: (SRA (SignExt16to32 x) ( CMOVZ (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 y (MOVWconst [-1]) (SGTUconst [32] y))) + // result: (SRA (SignExt16to32 x) ( CMOVZ 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 (ZeroExt8to32 y) (MOVWconst [-1]) (SGTUconst [32] (ZeroExt8to32 y)))) + // result: (SRA (SignExt16to32 x) ( CMOVZ (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)