From: Constantin Konstantinidis Date: Sat, 29 Aug 2020 09:10:50 +0000 (+0200) Subject: cmd/compile: enforce strongly typed rules for ARM (GOARM) X-Git-Tag: go1.16beta1~944 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=aacbd7c3aab5c3bf5d5f6cbfaa63db9d9fc2e3d5;p=gostls13.git cmd/compile: enforce strongly typed rules for ARM (GOARM) Toolstash-check successful for remaining rules using GOARM value. Change-Id: I254f80d17839ef4957c1b7afbdb4db363a3b9367 Reviewed-on: https://go-review.googlesource.com/c/go/+/240997 Run-TryBot: Giovanni Bajo TryBot-Result: Go Bot Reviewed-by: Keith Randall Trust: Giovanni Bajo --- diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index 2be347d98b..840b93bb53 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -65,17 +65,17 @@ // count trailing zero for ARMv5 and ARMv6 // 32 - CLZ(x&-x - 1) -(Ctz32 x) && objabi.GOARM<=6 -> +(Ctz32 x) && objabi.GOARM<=6 => (RSBconst [32] (CLZ (SUBconst (AND x (RSBconst [0] x)) [1]))) -(Ctz16 x) && objabi.GOARM<=6 -> +(Ctz16 x) && objabi.GOARM<=6 => (RSBconst [32] (CLZ (SUBconst (AND (ORconst [0x10000] x) (RSBconst [0] (ORconst [0x10000] x))) [1]))) -(Ctz8 x) && objabi.GOARM<=6 -> +(Ctz8 x) && objabi.GOARM<=6 => (RSBconst [32] (CLZ (SUBconst (AND (ORconst [0x100] x) (RSBconst [0] (ORconst [0x100] x))) [1]))) // count trailing zero for ARMv7 -(Ctz32 x) && objabi.GOARM==7 -> (CLZ (RBIT x)) -(Ctz16 x) && objabi.GOARM==7 -> (CLZ (RBIT (ORconst [0x10000] x))) -(Ctz8 x) && objabi.GOARM==7 -> (CLZ (RBIT (ORconst [0x100] x))) +(Ctz32 x) && objabi.GOARM==7 => (CLZ (RBIT x)) +(Ctz16 x) && objabi.GOARM==7 => (CLZ (RBIT (ORconst [0x10000] x))) +(Ctz8 x) && objabi.GOARM==7 => (CLZ (RBIT (ORconst [0x100] x))) // bit length (BitLen32 x) => (RSBconst [32] (CLZ x)) @@ -89,13 +89,13 @@ // t5 = x right rotate 8 bits -- (d, a, b, c ) // result = t4 ^ t5 -- (d, c, b, a ) // using shifted ops this can be done in 4 instructions. -(Bswap32 x) && objabi.GOARM==5 -> +(Bswap32 x) && objabi.GOARM==5 => (XOR (SRLconst (BICconst (XOR x (SRRconst [16] x)) [0xff0000]) [8]) (SRRconst x [8])) // byte swap for ARMv6 and above -(Bswap32 x) && objabi.GOARM>=6 -> (REV x) +(Bswap32 x) && objabi.GOARM>=6 => (REV x) // boolean ops -- booleans are represented with 0=false, 1=true (AndB ...) => (AND ...) @@ -1139,7 +1139,7 @@ // UBFX instruction is supported by ARMv6T2, ARMv7 and above versions, REV16 is supported by // ARMv6 and above versions. So for ARMv6, we need to match SLLconst, SRLconst and ORshiftLL. ((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (BFXU [int32(armBFAuxInt(8, 8))] x) x) => (REV16 x) -((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [24] (SLLconst [16] x)) x) && objabi.GOARM>=6 -> (REV16 x) +((ADDshiftLL|ORshiftLL|XORshiftLL) [8] (SRLconst [24] (SLLconst [16] x)) x) && objabi.GOARM>=6 => (REV16 x) // use indexed loads and stores (MOVWload [0] {sym} (ADD ptr idx) mem) && sym == nil => (MOVWloadidx ptr idx mem) @@ -1209,25 +1209,25 @@ (BIC x x) => (MOVWconst [0]) (ADD (MUL x y) a) => (MULA x y a) -(SUB a (MUL x y)) && objabi.GOARM == 7 -> (MULS x y a) -(RSB (MUL x y) a) && objabi.GOARM == 7 -> (MULS x y a) +(SUB a (MUL x y)) && objabi.GOARM == 7 => (MULS x y a) +(RSB (MUL x y) a) && objabi.GOARM == 7 => (MULS x y a) -(NEGF (MULF x y)) && objabi.GOARM >= 6 -> (NMULF x y) -(NEGD (MULD x y)) && objabi.GOARM >= 6 -> (NMULD x y) -(MULF (NEGF x) y) && objabi.GOARM >= 6 -> (NMULF x y) -(MULD (NEGD x) y) && objabi.GOARM >= 6 -> (NMULD x y) +(NEGF (MULF x y)) && objabi.GOARM >= 6 => (NMULF x y) +(NEGD (MULD x y)) && objabi.GOARM >= 6 => (NMULD x y) +(MULF (NEGF x) y) && objabi.GOARM >= 6 => (NMULF x y) +(MULD (NEGD x) y) && objabi.GOARM >= 6 => (NMULD x y) (NMULF (NEGF x) y) => (MULF x y) (NMULD (NEGD x) y) => (MULD x y) // the result will overwrite the addend, since they are in the same register -(ADDF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y) -(ADDF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y) -(ADDD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y) -(ADDD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y) -(SUBF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y) -(SUBF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y) -(SUBD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y) -(SUBD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y) +(ADDF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAF a x y) +(ADDF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSF a x y) +(ADDD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAD a x y) +(ADDD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSD a x y) +(SUBF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSF a x y) +(SUBF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAF a x y) +(SUBD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULSD a x y) +(SUBD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 => (MULAD a x y) (AND x (MVN y)) => (BIC x y) @@ -1259,8 +1259,8 @@ (CMPD x (MOVDconst [0])) => (CMPD0 x) // bit extraction -(SRAconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFX [(d-c)|(32-d)<<8] x) -(SRLconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFXU [(d-c)|(32-d)<<8] x) +(SRAconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 => (BFX [(d-c)|(32-d)<<8] x) +(SRLconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 => (BFXU [(d-c)|(32-d)<<8] x) // comparison simplification (CMP x (RSBconst [0] y)) => (CMN x y) diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index 594d7427c4..b790d28cac 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -2087,11 +2087,11 @@ func rewriteValueARM_OpARMADDshiftLL(v *Value) bool { // cond: objabi.GOARM>=6 // result: (REV16 x) for { - if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 { + if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 { break } v_0_0 := v_0.Args[0] - if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 { + if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 { break } x := v_0_0.Args[0] @@ -8555,11 +8555,11 @@ func rewriteValueARM_OpARMORshiftLL(v *Value) bool { // cond: objabi.GOARM>=6 // result: (REV16 x) for { - if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 { + if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 { break } v_0_0 := v_0.Args[0] - if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 { + if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 { break } x := v_0_0.Args[0] @@ -10466,17 +10466,17 @@ func rewriteValueARM_OpARMSRAconst(v *Value) bool { // cond: objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 // result: (BFX [(d-c)|(32-d)<<8] x) for { - d := v.AuxInt + d := auxIntToInt32(v.AuxInt) if v_0.Op != OpARMSLLconst { break } - c := v_0.AuxInt + c := auxIntToInt32(v_0.AuxInt) x := v_0.Args[0] if !(objabi.GOARM == 7 && uint64(d) >= uint64(c) && uint64(d) <= 31) { break } v.reset(OpARMBFX) - v.AuxInt = (d - c) | (32-d)<<8 + v.AuxInt = int32ToAuxInt((d - c) | (32-d)<<8) v.AddArg(x) return true } @@ -10518,17 +10518,17 @@ func rewriteValueARM_OpARMSRLconst(v *Value) bool { // cond: objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 // result: (BFXU [(d-c)|(32-d)<<8] x) for { - d := v.AuxInt + d := auxIntToInt32(v.AuxInt) if v_0.Op != OpARMSLLconst { break } - c := v_0.AuxInt + c := auxIntToInt32(v_0.AuxInt) x := v_0.Args[0] if !(objabi.GOARM == 7 && uint64(d) >= uint64(c) && uint64(d) <= 31) { break } v.reset(OpARMBFXU) - v.AuxInt = (d - c) | (32-d)<<8 + v.AuxInt = int32ToAuxInt((d - c) | (32-d)<<8) v.AddArg(x) return true } @@ -12594,11 +12594,11 @@ func rewriteValueARM_OpARMXORshiftLL(v *Value) bool { // cond: objabi.GOARM>=6 // result: (REV16 x) for { - if v.Type != typ.UInt16 || v.AuxInt != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || v_0.AuxInt != 24 { + if v.Type != typ.UInt16 || auxIntToInt32(v.AuxInt) != 8 || v_0.Op != OpARMSRLconst || v_0.Type != typ.UInt16 || auxIntToInt32(v_0.AuxInt) != 24 { break } v_0_0 := v_0.Args[0] - if v_0_0.Op != OpARMSLLconst || v_0_0.AuxInt != 16 { + if v_0_0.Op != OpARMSLLconst || auxIntToInt32(v_0_0.AuxInt) != 16 { break } x := v_0_0.Args[0] @@ -12951,18 +12951,18 @@ func rewriteValueARM_OpBswap32(v *Value) bool { v.reset(OpARMXOR) v.Type = t v0 := b.NewValue0(v.Pos, OpARMSRLconst, t) - v0.AuxInt = 8 + v0.AuxInt = int32ToAuxInt(8) v1 := b.NewValue0(v.Pos, OpARMBICconst, t) - v1.AuxInt = 0xff0000 + v1.AuxInt = int32ToAuxInt(0xff0000) v2 := b.NewValue0(v.Pos, OpARMXOR, t) v3 := b.NewValue0(v.Pos, OpARMSRRconst, t) - v3.AuxInt = 16 + v3.AuxInt = int32ToAuxInt(16) v3.AddArg(x) v2.AddArg2(x, v3) v1.AddArg(v2) v0.AddArg(v1) v4 := b.NewValue0(v.Pos, OpARMSRRconst, t) - v4.AuxInt = 8 + v4.AuxInt = int32ToAuxInt(8) v4.AddArg(x) v.AddArg2(v0, v4) return true @@ -13004,16 +13004,16 @@ func rewriteValueARM_OpCtz16(v *Value) bool { break } v.reset(OpARMRSBconst) - v.AuxInt = 32 + v.AuxInt = int32ToAuxInt(32) v0 := b.NewValue0(v.Pos, OpARMCLZ, t) v1 := b.NewValue0(v.Pos, OpARMSUBconst, typ.UInt32) - v1.AuxInt = 1 + v1.AuxInt = int32ToAuxInt(1) v2 := b.NewValue0(v.Pos, OpARMAND, typ.UInt32) v3 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32) - v3.AuxInt = 0x10000 + v3.AuxInt = int32ToAuxInt(0x10000) v3.AddArg(x) v4 := b.NewValue0(v.Pos, OpARMRSBconst, typ.UInt32) - v4.AuxInt = 0 + v4.AuxInt = int32ToAuxInt(0) v4.AddArg(v3) v2.AddArg2(v3, v4) v1.AddArg(v2) @@ -13034,7 +13034,7 @@ func rewriteValueARM_OpCtz16(v *Value) bool { v.Type = t v0 := b.NewValue0(v.Pos, OpARMRBIT, typ.UInt32) v1 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32) - v1.AuxInt = 0x10000 + v1.AuxInt = int32ToAuxInt(0x10000) v1.AddArg(x) v0.AddArg(v1) v.AddArg(v0) @@ -13055,13 +13055,13 @@ func rewriteValueARM_OpCtz32(v *Value) bool { break } v.reset(OpARMRSBconst) - v.AuxInt = 32 + v.AuxInt = int32ToAuxInt(32) v0 := b.NewValue0(v.Pos, OpARMCLZ, t) v1 := b.NewValue0(v.Pos, OpARMSUBconst, t) - v1.AuxInt = 1 + v1.AuxInt = int32ToAuxInt(1) v2 := b.NewValue0(v.Pos, OpARMAND, t) v3 := b.NewValue0(v.Pos, OpARMRSBconst, t) - v3.AuxInt = 0 + v3.AuxInt = int32ToAuxInt(0) v3.AddArg(x) v2.AddArg2(x, v3) v1.AddArg(v2) @@ -13101,16 +13101,16 @@ func rewriteValueARM_OpCtz8(v *Value) bool { break } v.reset(OpARMRSBconst) - v.AuxInt = 32 + v.AuxInt = int32ToAuxInt(32) v0 := b.NewValue0(v.Pos, OpARMCLZ, t) v1 := b.NewValue0(v.Pos, OpARMSUBconst, typ.UInt32) - v1.AuxInt = 1 + v1.AuxInt = int32ToAuxInt(1) v2 := b.NewValue0(v.Pos, OpARMAND, typ.UInt32) v3 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32) - v3.AuxInt = 0x100 + v3.AuxInt = int32ToAuxInt(0x100) v3.AddArg(x) v4 := b.NewValue0(v.Pos, OpARMRSBconst, typ.UInt32) - v4.AuxInt = 0 + v4.AuxInt = int32ToAuxInt(0) v4.AddArg(v3) v2.AddArg2(v3, v4) v1.AddArg(v2) @@ -13131,7 +13131,7 @@ func rewriteValueARM_OpCtz8(v *Value) bool { v.Type = t v0 := b.NewValue0(v.Pos, OpARMRBIT, typ.UInt32) v1 := b.NewValue0(v.Pos, OpARMORconst, typ.UInt32) - v1.AuxInt = 0x100 + v1.AuxInt = int32ToAuxInt(0x100) v1.AddArg(x) v0.AddArg(v1) v.AddArg(v0)