From a3374fa0f8ffe27d3a1e118b75b484ce56c7af2e Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 26 Apr 2020 13:02:32 -0700 Subject: [PATCH] cmd/compile: convert more generic rules to typed aux Passes toolstash-check. Change-Id: I07d79d809babfeda883a49f0b21ab27ede5381cb Reviewed-on: https://go-review.googlesource.com/c/go/+/230211 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- .../compile/internal/ssa/gen/generic.rules | 64 ++-- src/cmd/compile/internal/ssa/magic.go | 7 + .../compile/internal/ssa/rewritegeneric.go | 274 +++++++++--------- 3 files changed, 176 insertions(+), 169 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 814c71c619..412e7aa16b 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -1171,44 +1171,44 @@ (Const64 [63]))) // Unsigned mod by power of 2 constant. -(Mod8u n (Const8 [c])) && isPowerOfTwo(c&0xff) -> (And8 n (Const8 [(c&0xff)-1])) -(Mod16u n (Const16 [c])) && isPowerOfTwo(c&0xffff) -> (And16 n (Const16 [(c&0xffff)-1])) -(Mod32u n (Const32 [c])) && isPowerOfTwo(c&0xffffffff) -> (And32 n (Const32 [(c&0xffffffff)-1])) -(Mod64u n (Const64 [c])) && isPowerOfTwo(c) -> (And64 n (Const64 [c-1])) -(Mod64u n (Const64 [-1<<63])) -> (And64 n (Const64 [1<<63-1])) +(Mod8u n (Const8 [c])) && isPowerOfTwo8(c) => (And8 n (Const8 [c-1])) +(Mod16u n (Const16 [c])) && isPowerOfTwo16(c) => (And16 n (Const16 [c-1])) +(Mod32u n (Const32 [c])) && isPowerOfTwo32(c) => (And32 n (Const32 [c-1])) +(Mod64u n (Const64 [c])) && isPowerOfTwo64(c) => (And64 n (Const64 [c-1])) +(Mod64u n (Const64 [-1<<63])) => (And64 n (Const64 [1<<63-1])) // Signed non-negative mod by power of 2 constant. -(Mod8 n (Const8 [c])) && isNonNegative(n) && isPowerOfTwo(c&0xff) -> (And8 n (Const8 [(c&0xff)-1])) -(Mod16 n (Const16 [c])) && isNonNegative(n) && isPowerOfTwo(c&0xffff) -> (And16 n (Const16 [(c&0xffff)-1])) -(Mod32 n (Const32 [c])) && isNonNegative(n) && isPowerOfTwo(c&0xffffffff) -> (And32 n (Const32 [(c&0xffffffff)-1])) -(Mod64 n (Const64 [c])) && isNonNegative(n) && isPowerOfTwo(c) -> (And64 n (Const64 [c-1])) -(Mod64 n (Const64 [-1<<63])) && isNonNegative(n) -> n +(Mod8 n (Const8 [c])) && isNonNegative(n) && isPowerOfTwo8(c) => (And8 n (Const8 [c-1])) +(Mod16 n (Const16 [c])) && isNonNegative(n) && isPowerOfTwo16(c) => (And16 n (Const16 [c-1])) +(Mod32 n (Const32 [c])) && isNonNegative(n) && isPowerOfTwo32(c) => (And32 n (Const32 [c-1])) +(Mod64 n (Const64 [c])) && isNonNegative(n) && isPowerOfTwo64(c) => (And64 n (Const64 [c-1])) +(Mod64 n (Const64 [-1<<63])) && isNonNegative(n) => n // Signed mod by negative constant. -(Mod8 n (Const8 [c])) && c < 0 && c != -1<<7 -> (Mod8 n (Const8 [-c])) -(Mod16 n (Const16 [c])) && c < 0 && c != -1<<15 -> (Mod16 n (Const16 [-c])) -(Mod32 n (Const32 [c])) && c < 0 && c != -1<<31 -> (Mod32 n (Const32 [-c])) -(Mod64 n (Const64 [c])) && c < 0 && c != -1<<63 -> (Mod64 n (Const64 [-c])) +(Mod8 n (Const8 [c])) && c < 0 && c != -1<<7 => (Mod8 n (Const8 [-c])) +(Mod16 n (Const16 [c])) && c < 0 && c != -1<<15 => (Mod16 n (Const16 [-c])) +(Mod32 n (Const32 [c])) && c < 0 && c != -1<<31 => (Mod32 n (Const32 [-c])) +(Mod64 n (Const64 [c])) && c < 0 && c != -1<<63 => (Mod64 n (Const64 [-c])) // All other mods by constants, do A%B = A-(A/B*B). // This implements % with two * and a bunch of ancillary ops. // One of the * is free if the user's code also computes A/B. (Mod8 x (Const8 [c])) && x.Op != OpConst8 && (c > 0 || c == -1<<7) - -> (Sub8 x (Mul8 (Div8 x (Const8 [c])) (Const8 [c]))) + => (Sub8 x (Mul8 (Div8 x (Const8 [c])) (Const8 [c]))) (Mod16 x (Const16 [c])) && x.Op != OpConst16 && (c > 0 || c == -1<<15) - -> (Sub16 x (Mul16 (Div16 x (Const16 [c])) (Const16 [c]))) + => (Sub16 x (Mul16 (Div16 x (Const16 [c])) (Const16 [c]))) (Mod32 x (Const32 [c])) && x.Op != OpConst32 && (c > 0 || c == -1<<31) - -> (Sub32 x (Mul32 (Div32 x (Const32 [c])) (Const32 [c]))) + => (Sub32 x (Mul32 (Div32 x (Const32 [c])) (Const32 [c]))) (Mod64 x (Const64 [c])) && x.Op != OpConst64 && (c > 0 || c == -1<<63) - -> (Sub64 x (Mul64 (Div64 x (Const64 [c])) (Const64 [c]))) -(Mod8u x (Const8 [c])) && x.Op != OpConst8 && c > 0 && umagicOK(8, c) - -> (Sub8 x (Mul8 (Div8u x (Const8 [c])) (Const8 [c]))) -(Mod16u x (Const16 [c])) && x.Op != OpConst16 && c > 0 && umagicOK(16,c) - -> (Sub16 x (Mul16 (Div16u x (Const16 [c])) (Const16 [c]))) -(Mod32u x (Const32 [c])) && x.Op != OpConst32 && c > 0 && umagicOK(32,c) - -> (Sub32 x (Mul32 (Div32u x (Const32 [c])) (Const32 [c]))) -(Mod64u x (Const64 [c])) && x.Op != OpConst64 && c > 0 && umagicOK(64,c) - -> (Sub64 x (Mul64 (Div64u x (Const64 [c])) (Const64 [c]))) + => (Sub64 x (Mul64 (Div64 x (Const64 [c])) (Const64 [c]))) +(Mod8u x (Const8 [c])) && x.Op != OpConst8 && c > 0 && umagicOK8( c) + => (Sub8 x (Mul8 (Div8u x (Const8 [c])) (Const8 [c]))) +(Mod16u x (Const16 [c])) && x.Op != OpConst16 && c > 0 && umagicOK16(c) + => (Sub16 x (Mul16 (Div16u x (Const16 [c])) (Const16 [c]))) +(Mod32u x (Const32 [c])) && x.Op != OpConst32 && c > 0 && umagicOK32(c) + => (Sub32 x (Mul32 (Div32u x (Const32 [c])) (Const32 [c]))) +(Mod64u x (Const64 [c])) && x.Op != OpConst64 && c > 0 && umagicOK64(c) + => (Sub64 x (Mul64 (Div64u x (Const64 [c])) (Const64 [c]))) // For architectures without rotates on less than 32-bits, promote these checks to 32-bit. (Eq8 (Mod8u x (Const8 [c])) (Const8 [0])) && x.Op != OpConst8 && udivisibleOK(8,c) && !hasSmallRotate(config) -> @@ -1745,7 +1745,7 @@ (Const64 [k])) (Const64 [k])) ) && k > 0 && k < 7 && kbar == 8 - k - -> ((Eq8|Neq8) (And8 n (Const8 [int64(1< [0])) + => ((Eq8|Neq8) (And8 n (Const8 [1< [0])) ((Eq16|Neq16) n (Lsh16x64 (Rsh16x64 @@ -1753,7 +1753,7 @@ (Const64 [k])) (Const64 [k])) ) && k > 0 && k < 15 && kbar == 16 - k - -> ((Eq16|Neq16) (And16 n (Const16 [int64(1< [0])) + => ((Eq16|Neq16) (And16 n (Const16 [1< [0])) ((Eq32|Neq32) n (Lsh32x64 (Rsh32x64 @@ -1761,7 +1761,7 @@ (Const64 [k])) (Const64 [k])) ) && k > 0 && k < 31 && kbar == 32 - k - -> ((Eq32|Neq32) (And32 n (Const32 [int64(1< [0])) + => ((Eq32|Neq32) (And32 n (Const32 [1< [0])) ((Eq64|Neq64) n (Lsh64x64 (Rsh64x64 @@ -1769,10 +1769,10 @@ (Const64 [k])) (Const64 [k])) ) && k > 0 && k < 63 && kbar == 64 - k - -> ((Eq64|Neq64) (And64 n (Const64 [int64(1< [0])) + => ((Eq64|Neq64) (And64 n (Const64 [1< [0])) -(Eq(8|16|32|64) s:(Sub(8|16|32|64) x y) (Const(8|16|32|64) [0])) && s.Uses == 1 -> (Eq(8|16|32|64) x y) -(Neq(8|16|32|64) s:(Sub(8|16|32|64) x y) (Const(8|16|32|64) [0])) && s.Uses == 1 -> (Neq(8|16|32|64) x y) +(Eq(8|16|32|64) s:(Sub(8|16|32|64) x y) (Const(8|16|32|64) [0])) && s.Uses == 1 => (Eq(8|16|32|64) x y) +(Neq(8|16|32|64) s:(Sub(8|16|32|64) x y) (Const(8|16|32|64) [0])) && s.Uses == 1 => (Neq(8|16|32|64) x y) // Optimize bitsets (Eq8 (And8 x (Const8 [y])) (Const8 [y])) && oneBit8(y) diff --git a/src/cmd/compile/internal/ssa/magic.go b/src/cmd/compile/internal/ssa/magic.go index e0c627184b..6e90d06ae0 100644 --- a/src/cmd/compile/internal/ssa/magic.go +++ b/src/cmd/compile/internal/ssa/magic.go @@ -96,6 +96,13 @@ func umagicOK(n uint, c int64) bool { return d&(d-1) != 0 } +// umagicOKn reports whether we should strength reduce an n-bit divide by c. +// We can strength reduce when c != 0 and c is not a power of two. +func umagicOK8(c int8) bool { return c&(c-1) != 0 } +func umagicOK16(c int16) bool { return c&(c-1) != 0 } +func umagicOK32(c int32) bool { return c&(c-1) != 0 } +func umagicOK64(c int64) bool { return c&(c-1) != 0 } + type umagicData struct { s int64 // ⎡log2(c)⎤ m uint64 // ⎡2^(n+s)/c⎤ - 2^n diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 870465da03..adf14c24bc 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -6213,7 +6213,7 @@ func rewriteValuegeneric_OpEq16(v *Value) bool { } // match: (Eq16 n (Lsh16x64 (Rsh16x64 (Add16 n (Rsh16Ux64 (Rsh16x64 n (Const64 [15])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 15 && kbar == 16 - k - // result: (Eq16 (And16 n (Const16 [int64(1< [0])) + // result: (Eq16 (And16 n (Const16 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -6248,30 +6248,30 @@ func rewriteValuegeneric_OpEq16(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 15 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 15 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 15 && kbar == 16-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 15 && kbar == 16-k) { continue } v.reset(OpEq16) v0 := b.NewValue0(v.Pos, OpAnd16, t) v1 := b.NewValue0(v.Pos, OpConst16, t) - v1.AuxInt = int64(1< n (Rsh32Ux64 (Rsh32x64 n (Const64 [31])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 31 && kbar == 32 - k - // result: (Eq32 (And32 n (Const32 [int64(1< [0])) + // result: (Eq32 (And32 n (Const32 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -7112,30 +7112,30 @@ func rewriteValuegeneric_OpEq32(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 31 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 31 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 31 && kbar == 32-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 31 && kbar == 32-k) { continue } v.reset(OpEq32) v0 := b.NewValue0(v.Pos, OpAnd32, t) v1 := b.NewValue0(v.Pos, OpConst32, t) - v1.AuxInt = int64(1< n (Rsh64Ux64 (Rsh64x64 n (Const64 [63])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 63 && kbar == 64 - k - // result: (Eq64 (And64 n (Const64 [int64(1< [0])) + // result: (Eq64 (And64 n (Const64 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -7693,30 +7693,30 @@ func rewriteValuegeneric_OpEq64(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 63 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 63 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 63 && kbar == 64-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 63 && kbar == 64-k) { continue } v.reset(OpEq64) v0 := b.NewValue0(v.Pos, OpAnd64, t) v1 := b.NewValue0(v.Pos, OpConst64, t) - v1.AuxInt = int64(1< n (Rsh8Ux64 (Rsh8x64 n (Const64 [ 7])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 7 && kbar == 8 - k - // result: (Eq8 (And8 n (Const8 [int64(1< [0])) + // result: (Eq8 (And8 n (Const8 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -8115,30 +8115,30 @@ func rewriteValuegeneric_OpEq8(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 7 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 7 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 7 && kbar == 8-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 7 && kbar == 8-k) { continue } v.reset(OpEq8) v0 := b.NewValue0(v.Pos, OpAnd8, t) v1 := b.NewValue0(v.Pos, OpConst8, t) - v1.AuxInt = int64(1< n (Const16 [c])) - // cond: isNonNegative(n) && isPowerOfTwo(c&0xffff) - // result: (And16 n (Const16 [(c&0xffff)-1])) + // cond: isNonNegative(n) && isPowerOfTwo16(c) + // result: (And16 n (Const16 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst16 { break } - c := v_1.AuxInt - if !(isNonNegative(n) && isPowerOfTwo(c&0xffff)) { + c := auxIntToInt16(v_1.AuxInt) + if !(isNonNegative(n) && isPowerOfTwo16(c)) { break } v.reset(OpAnd16) v0 := b.NewValue0(v.Pos, OpConst16, t) - v0.AuxInt = (c & 0xffff) - 1 + v0.AuxInt = int16ToAuxInt(c - 1) v.AddArg2(n, v0) return true } @@ -11803,14 +11803,14 @@ func rewriteValuegeneric_OpMod16(v *Value) bool { if v_1.Op != OpConst16 { break } - c := v_1.AuxInt + c := auxIntToInt16(v_1.AuxInt) if !(c < 0 && c != -1<<15) { break } v.reset(OpMod16) v.Type = t v0 := b.NewValue0(v.Pos, OpConst16, t) - v0.AuxInt = -c + v0.AuxInt = int16ToAuxInt(-c) v.AddArg2(n, v0) return true } @@ -11823,7 +11823,7 @@ func rewriteValuegeneric_OpMod16(v *Value) bool { if v_1.Op != OpConst16 { break } - c := v_1.AuxInt + c := auxIntToInt16(v_1.AuxInt) if !(x.Op != OpConst16 && (c > 0 || c == -1<<15)) { break } @@ -11831,7 +11831,7 @@ func rewriteValuegeneric_OpMod16(v *Value) bool { v0 := b.NewValue0(v.Pos, OpMul16, t) v1 := b.NewValue0(v.Pos, OpDiv16, t) v2 := b.NewValue0(v.Pos, OpConst16, t) - v2.AuxInt = c + v2.AuxInt = int16ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -11863,26 +11863,26 @@ func rewriteValuegeneric_OpMod16u(v *Value) bool { return true } // match: (Mod16u n (Const16 [c])) - // cond: isPowerOfTwo(c&0xffff) - // result: (And16 n (Const16 [(c&0xffff)-1])) + // cond: isPowerOfTwo16(c) + // result: (And16 n (Const16 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst16 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c & 0xffff)) { + c := auxIntToInt16(v_1.AuxInt) + if !(isPowerOfTwo16(c)) { break } v.reset(OpAnd16) v0 := b.NewValue0(v.Pos, OpConst16, t) - v0.AuxInt = (c & 0xffff) - 1 + v0.AuxInt = int16ToAuxInt(c - 1) v.AddArg2(n, v0) return true } // match: (Mod16u x (Const16 [c])) - // cond: x.Op != OpConst16 && c > 0 && umagicOK(16,c) + // cond: x.Op != OpConst16 && c > 0 && umagicOK16(c) // result: (Sub16 x (Mul16 (Div16u x (Const16 [c])) (Const16 [c]))) for { t := v.Type @@ -11890,15 +11890,15 @@ func rewriteValuegeneric_OpMod16u(v *Value) bool { if v_1.Op != OpConst16 { break } - c := v_1.AuxInt - if !(x.Op != OpConst16 && c > 0 && umagicOK(16, c)) { + c := auxIntToInt16(v_1.AuxInt) + if !(x.Op != OpConst16 && c > 0 && umagicOK16(c)) { break } v.reset(OpSub16) v0 := b.NewValue0(v.Pos, OpMul16, t) v1 := b.NewValue0(v.Pos, OpDiv16u, t) v2 := b.NewValue0(v.Pos, OpConst16, t) - v2.AuxInt = c + v2.AuxInt = int16ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -11930,21 +11930,21 @@ func rewriteValuegeneric_OpMod32(v *Value) bool { return true } // match: (Mod32 n (Const32 [c])) - // cond: isNonNegative(n) && isPowerOfTwo(c&0xffffffff) - // result: (And32 n (Const32 [(c&0xffffffff)-1])) + // cond: isNonNegative(n) && isPowerOfTwo32(c) + // result: (And32 n (Const32 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst32 { break } - c := v_1.AuxInt - if !(isNonNegative(n) && isPowerOfTwo(c&0xffffffff)) { + c := auxIntToInt32(v_1.AuxInt) + if !(isNonNegative(n) && isPowerOfTwo32(c)) { break } v.reset(OpAnd32) v0 := b.NewValue0(v.Pos, OpConst32, t) - v0.AuxInt = (c & 0xffffffff) - 1 + v0.AuxInt = int32ToAuxInt(c - 1) v.AddArg2(n, v0) return true } @@ -11957,14 +11957,14 @@ func rewriteValuegeneric_OpMod32(v *Value) bool { if v_1.Op != OpConst32 { break } - c := v_1.AuxInt + c := auxIntToInt32(v_1.AuxInt) if !(c < 0 && c != -1<<31) { break } v.reset(OpMod32) v.Type = t v0 := b.NewValue0(v.Pos, OpConst32, t) - v0.AuxInt = -c + v0.AuxInt = int32ToAuxInt(-c) v.AddArg2(n, v0) return true } @@ -11977,7 +11977,7 @@ func rewriteValuegeneric_OpMod32(v *Value) bool { if v_1.Op != OpConst32 { break } - c := v_1.AuxInt + c := auxIntToInt32(v_1.AuxInt) if !(x.Op != OpConst32 && (c > 0 || c == -1<<31)) { break } @@ -11985,7 +11985,7 @@ func rewriteValuegeneric_OpMod32(v *Value) bool { v0 := b.NewValue0(v.Pos, OpMul32, t) v1 := b.NewValue0(v.Pos, OpDiv32, t) v2 := b.NewValue0(v.Pos, OpConst32, t) - v2.AuxInt = c + v2.AuxInt = int32ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -12017,26 +12017,26 @@ func rewriteValuegeneric_OpMod32u(v *Value) bool { return true } // match: (Mod32u n (Const32 [c])) - // cond: isPowerOfTwo(c&0xffffffff) - // result: (And32 n (Const32 [(c&0xffffffff)-1])) + // cond: isPowerOfTwo32(c) + // result: (And32 n (Const32 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst32 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c & 0xffffffff)) { + c := auxIntToInt32(v_1.AuxInt) + if !(isPowerOfTwo32(c)) { break } v.reset(OpAnd32) v0 := b.NewValue0(v.Pos, OpConst32, t) - v0.AuxInt = (c & 0xffffffff) - 1 + v0.AuxInt = int32ToAuxInt(c - 1) v.AddArg2(n, v0) return true } // match: (Mod32u x (Const32 [c])) - // cond: x.Op != OpConst32 && c > 0 && umagicOK(32,c) + // cond: x.Op != OpConst32 && c > 0 && umagicOK32(c) // result: (Sub32 x (Mul32 (Div32u x (Const32 [c])) (Const32 [c]))) for { t := v.Type @@ -12044,15 +12044,15 @@ func rewriteValuegeneric_OpMod32u(v *Value) bool { if v_1.Op != OpConst32 { break } - c := v_1.AuxInt - if !(x.Op != OpConst32 && c > 0 && umagicOK(32, c)) { + c := auxIntToInt32(v_1.AuxInt) + if !(x.Op != OpConst32 && c > 0 && umagicOK32(c)) { break } v.reset(OpSub32) v0 := b.NewValue0(v.Pos, OpMul32, t) v1 := b.NewValue0(v.Pos, OpDiv32u, t) v2 := b.NewValue0(v.Pos, OpConst32, t) - v2.AuxInt = c + v2.AuxInt = int32ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -12084,7 +12084,7 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { return true } // match: (Mod64 n (Const64 [c])) - // cond: isNonNegative(n) && isPowerOfTwo(c) + // cond: isNonNegative(n) && isPowerOfTwo64(c) // result: (And64 n (Const64 [c-1])) for { t := v.Type @@ -12092,13 +12092,13 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { if v_1.Op != OpConst64 { break } - c := v_1.AuxInt - if !(isNonNegative(n) && isPowerOfTwo(c)) { + c := auxIntToInt64(v_1.AuxInt) + if !(isNonNegative(n) && isPowerOfTwo64(c)) { break } v.reset(OpAnd64) v0 := b.NewValue0(v.Pos, OpConst64, t) - v0.AuxInt = c - 1 + v0.AuxInt = int64ToAuxInt(c - 1) v.AddArg2(n, v0) return true } @@ -12107,7 +12107,7 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { // result: n for { n := v_0 - if v_1.Op != OpConst64 || v_1.AuxInt != -1<<63 || !(isNonNegative(n)) { + if v_1.Op != OpConst64 || auxIntToInt64(v_1.AuxInt) != -1<<63 || !(isNonNegative(n)) { break } v.copyOf(n) @@ -12122,14 +12122,14 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { if v_1.Op != OpConst64 { break } - c := v_1.AuxInt + c := auxIntToInt64(v_1.AuxInt) if !(c < 0 && c != -1<<63) { break } v.reset(OpMod64) v.Type = t v0 := b.NewValue0(v.Pos, OpConst64, t) - v0.AuxInt = -c + v0.AuxInt = int64ToAuxInt(-c) v.AddArg2(n, v0) return true } @@ -12142,7 +12142,7 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { if v_1.Op != OpConst64 { break } - c := v_1.AuxInt + c := auxIntToInt64(v_1.AuxInt) if !(x.Op != OpConst64 && (c > 0 || c == -1<<63)) { break } @@ -12150,7 +12150,7 @@ func rewriteValuegeneric_OpMod64(v *Value) bool { v0 := b.NewValue0(v.Pos, OpMul64, t) v1 := b.NewValue0(v.Pos, OpDiv64, t) v2 := b.NewValue0(v.Pos, OpConst64, t) - v2.AuxInt = c + v2.AuxInt = int64ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -12182,7 +12182,7 @@ func rewriteValuegeneric_OpMod64u(v *Value) bool { return true } // match: (Mod64u n (Const64 [c])) - // cond: isPowerOfTwo(c) + // cond: isPowerOfTwo64(c) // result: (And64 n (Const64 [c-1])) for { t := v.Type @@ -12190,13 +12190,13 @@ func rewriteValuegeneric_OpMod64u(v *Value) bool { if v_1.Op != OpConst64 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + c := auxIntToInt64(v_1.AuxInt) + if !(isPowerOfTwo64(c)) { break } v.reset(OpAnd64) v0 := b.NewValue0(v.Pos, OpConst64, t) - v0.AuxInt = c - 1 + v0.AuxInt = int64ToAuxInt(c - 1) v.AddArg2(n, v0) return true } @@ -12205,17 +12205,17 @@ func rewriteValuegeneric_OpMod64u(v *Value) bool { for { t := v.Type n := v_0 - if v_1.Op != OpConst64 || v_1.AuxInt != -1<<63 { + if v_1.Op != OpConst64 || auxIntToInt64(v_1.AuxInt) != -1<<63 { break } v.reset(OpAnd64) v0 := b.NewValue0(v.Pos, OpConst64, t) - v0.AuxInt = 1<<63 - 1 + v0.AuxInt = int64ToAuxInt(1<<63 - 1) v.AddArg2(n, v0) return true } // match: (Mod64u x (Const64 [c])) - // cond: x.Op != OpConst64 && c > 0 && umagicOK(64,c) + // cond: x.Op != OpConst64 && c > 0 && umagicOK64(c) // result: (Sub64 x (Mul64 (Div64u x (Const64 [c])) (Const64 [c]))) for { t := v.Type @@ -12223,15 +12223,15 @@ func rewriteValuegeneric_OpMod64u(v *Value) bool { if v_1.Op != OpConst64 { break } - c := v_1.AuxInt - if !(x.Op != OpConst64 && c > 0 && umagicOK(64, c)) { + c := auxIntToInt64(v_1.AuxInt) + if !(x.Op != OpConst64 && c > 0 && umagicOK64(c)) { break } v.reset(OpSub64) v0 := b.NewValue0(v.Pos, OpMul64, t) v1 := b.NewValue0(v.Pos, OpDiv64u, t) v2 := b.NewValue0(v.Pos, OpConst64, t) - v2.AuxInt = c + v2.AuxInt = int64ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -12263,21 +12263,21 @@ func rewriteValuegeneric_OpMod8(v *Value) bool { return true } // match: (Mod8 n (Const8 [c])) - // cond: isNonNegative(n) && isPowerOfTwo(c&0xff) - // result: (And8 n (Const8 [(c&0xff)-1])) + // cond: isNonNegative(n) && isPowerOfTwo8(c) + // result: (And8 n (Const8 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst8 { break } - c := v_1.AuxInt - if !(isNonNegative(n) && isPowerOfTwo(c&0xff)) { + c := auxIntToInt8(v_1.AuxInt) + if !(isNonNegative(n) && isPowerOfTwo8(c)) { break } v.reset(OpAnd8) v0 := b.NewValue0(v.Pos, OpConst8, t) - v0.AuxInt = (c & 0xff) - 1 + v0.AuxInt = int8ToAuxInt(c - 1) v.AddArg2(n, v0) return true } @@ -12290,14 +12290,14 @@ func rewriteValuegeneric_OpMod8(v *Value) bool { if v_1.Op != OpConst8 { break } - c := v_1.AuxInt + c := auxIntToInt8(v_1.AuxInt) if !(c < 0 && c != -1<<7) { break } v.reset(OpMod8) v.Type = t v0 := b.NewValue0(v.Pos, OpConst8, t) - v0.AuxInt = -c + v0.AuxInt = int8ToAuxInt(-c) v.AddArg2(n, v0) return true } @@ -12310,7 +12310,7 @@ func rewriteValuegeneric_OpMod8(v *Value) bool { if v_1.Op != OpConst8 { break } - c := v_1.AuxInt + c := auxIntToInt8(v_1.AuxInt) if !(x.Op != OpConst8 && (c > 0 || c == -1<<7)) { break } @@ -12318,7 +12318,7 @@ func rewriteValuegeneric_OpMod8(v *Value) bool { v0 := b.NewValue0(v.Pos, OpMul8, t) v1 := b.NewValue0(v.Pos, OpDiv8, t) v2 := b.NewValue0(v.Pos, OpConst8, t) - v2.AuxInt = c + v2.AuxInt = int8ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -12350,26 +12350,26 @@ func rewriteValuegeneric_OpMod8u(v *Value) bool { return true } // match: (Mod8u n (Const8 [c])) - // cond: isPowerOfTwo(c&0xff) - // result: (And8 n (Const8 [(c&0xff)-1])) + // cond: isPowerOfTwo8(c) + // result: (And8 n (Const8 [c-1])) for { t := v.Type n := v_0 if v_1.Op != OpConst8 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c & 0xff)) { + c := auxIntToInt8(v_1.AuxInt) + if !(isPowerOfTwo8(c)) { break } v.reset(OpAnd8) v0 := b.NewValue0(v.Pos, OpConst8, t) - v0.AuxInt = (c & 0xff) - 1 + v0.AuxInt = int8ToAuxInt(c - 1) v.AddArg2(n, v0) return true } // match: (Mod8u x (Const8 [c])) - // cond: x.Op != OpConst8 && c > 0 && umagicOK(8, c) + // cond: x.Op != OpConst8 && c > 0 && umagicOK8( c) // result: (Sub8 x (Mul8 (Div8u x (Const8 [c])) (Const8 [c]))) for { t := v.Type @@ -12377,15 +12377,15 @@ func rewriteValuegeneric_OpMod8u(v *Value) bool { if v_1.Op != OpConst8 { break } - c := v_1.AuxInt - if !(x.Op != OpConst8 && c > 0 && umagicOK(8, c)) { + c := auxIntToInt8(v_1.AuxInt) + if !(x.Op != OpConst8 && c > 0 && umagicOK8(c)) { break } v.reset(OpSub8) v0 := b.NewValue0(v.Pos, OpMul8, t) v1 := b.NewValue0(v.Pos, OpDiv8u, t) v2 := b.NewValue0(v.Pos, OpConst8, t) - v2.AuxInt = c + v2.AuxInt = int8ToAuxInt(c) v1.AddArg2(x, v2) v0.AddArg2(v1, v2) v.AddArg2(x, v0) @@ -14816,7 +14816,7 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { } // match: (Neq16 n (Lsh16x64 (Rsh16x64 (Add16 n (Rsh16Ux64 (Rsh16x64 n (Const64 [15])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 15 && kbar == 16 - k - // result: (Neq16 (And16 n (Const16 [int64(1< [0])) + // result: (Neq16 (And16 n (Const16 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -14851,30 +14851,30 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 15 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 15 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 15 && kbar == 16-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 15 && kbar == 16-k) { continue } v.reset(OpNeq16) v0 := b.NewValue0(v.Pos, OpAnd16, t) v1 := b.NewValue0(v.Pos, OpConst16, t) - v1.AuxInt = int64(1< n (Rsh32Ux64 (Rsh32x64 n (Const64 [31])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 31 && kbar == 32 - k - // result: (Neq32 (And32 n (Const32 [int64(1< [0])) + // result: (Neq32 (And32 n (Const32 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -15038,30 +15038,30 @@ func rewriteValuegeneric_OpNeq32(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 31 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 31 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 31 && kbar == 32-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 31 && kbar == 32-k) { continue } v.reset(OpNeq32) v0 := b.NewValue0(v.Pos, OpAnd32, t) v1 := b.NewValue0(v.Pos, OpConst32, t) - v1.AuxInt = int64(1< n (Rsh64Ux64 (Rsh64x64 n (Const64 [63])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 63 && kbar == 64 - k - // result: (Neq64 (And64 n (Const64 [int64(1< [0])) + // result: (Neq64 (And64 n (Const64 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -15248,30 +15248,30 @@ func rewriteValuegeneric_OpNeq64(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 63 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 63 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 63 && kbar == 64-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 63 && kbar == 64-k) { continue } v.reset(OpNeq64) v0 := b.NewValue0(v.Pos, OpAnd64, t) v1 := b.NewValue0(v.Pos, OpConst64, t) - v1.AuxInt = int64(1< n (Rsh8Ux64 (Rsh8x64 n (Const64 [ 7])) (Const64 [kbar]))) (Const64 [k])) (Const64 [k])) ) // cond: k > 0 && k < 7 && kbar == 8 - k - // result: (Neq8 (And8 n (Const8 [int64(1< [0])) + // result: (Neq8 (And8 n (Const8 [1< [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { n := v_0 @@ -15458,30 +15458,30 @@ func rewriteValuegeneric_OpNeq8(v *Value) bool { continue } v_1_0_0_1_0_1 := v_1_0_0_1_0.Args[1] - if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || v_1_0_0_1_0_1.AuxInt != 7 { + if v_1_0_0_1_0_1.Op != OpConst64 || v_1_0_0_1_0_1.Type != typ.UInt64 || auxIntToInt64(v_1_0_0_1_0_1.AuxInt) != 7 { continue } v_1_0_0_1_1 := v_1_0_0_1.Args[1] if v_1_0_0_1_1.Op != OpConst64 || v_1_0_0_1_1.Type != typ.UInt64 { continue } - kbar := v_1_0_0_1_1.AuxInt + kbar := auxIntToInt64(v_1_0_0_1_1.AuxInt) v_1_0_1 := v_1_0.Args[1] if v_1_0_1.Op != OpConst64 || v_1_0_1.Type != typ.UInt64 { continue } - k := v_1_0_1.AuxInt + k := auxIntToInt64(v_1_0_1.AuxInt) v_1_1 := v_1.Args[1] - if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || v_1_1.AuxInt != k || !(k > 0 && k < 7 && kbar == 8-k) { + if v_1_1.Op != OpConst64 || v_1_1.Type != typ.UInt64 || auxIntToInt64(v_1_1.AuxInt) != k || !(k > 0 && k < 7 && kbar == 8-k) { continue } v.reset(OpNeq8) v0 := b.NewValue0(v.Pos, OpAnd8, t) v1 := b.NewValue0(v.Pos, OpConst8, t) - v1.AuxInt = int64(1<