From 12665b9a067789004ca45cedcd3ebbbdc143f1d7 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 20 Apr 2020 14:36:40 -0700 Subject: [PATCH] cmd/compile: convert two generic rules to be typed Prelude to changing the rules. Passes toolstash-check. Change-Id: I22fead7f74d2cf97bb3fbeb22741125b42914c43 Reviewed-on: https://go-review.googlesource.com/c/go/+/229123 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- .../compile/internal/ssa/gen/generic.rules | 20 ++++- .../compile/internal/ssa/rewritegeneric.go | 80 +++++++++---------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 15d80afb45..e81e7d733e 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -1775,10 +1775,22 @@ (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 -(Eq(8|16|32|64) (And(8|16|32|64) x (Const(8|16|32|64) [y])) (Const(8|16|32|64) [y])) && isPowerOfTwo(y) - -> (Neq(8|16|32|64) (And(8|16|32|64) x (Const(8|16|32|64) [y])) (Const(8|16|32|64) [0])) -(Neq(8|16|32|64) (And(8|16|32|64) x (Const(8|16|32|64) [y])) (Const(8|16|32|64) [y])) && isPowerOfTwo(y) - -> (Eq(8|16|32|64) (And(8|16|32|64) x (Const(8|16|32|64) [y])) (Const(8|16|32|64) [0])) +(Eq8 (And8 x (Const8 [y])) (Const8 [y])) && isPowerOfTwo8(y) + => (Neq8 (And8 x (Const8 [y])) (Const8 [0])) +(Eq16 (And16 x (Const16 [y])) (Const16 [y])) && isPowerOfTwo16(y) + => (Neq16 (And16 x (Const16 [y])) (Const16 [0])) +(Eq32 (And32 x (Const32 [y])) (Const32 [y])) && isPowerOfTwo32(y) + => (Neq32 (And32 x (Const32 [y])) (Const32 [0])) +(Eq64 (And64 x (Const64 [y])) (Const64 [y])) && isPowerOfTwo64(y) + => (Neq64 (And64 x (Const64 [y])) (Const64 [0])) +(Neq8 (And8 x (Const8 [y])) (Const8 [y])) && isPowerOfTwo8(y) + => (Eq8 (And8 x (Const8 [y])) (Const8 [0])) +(Neq16 (And16 x (Const16 [y])) (Const16 [y])) && isPowerOfTwo16(y) + => (Eq16 (And16 x (Const16 [y])) (Const16 [0])) +(Neq32 (And32 x (Const32 [y])) (Const32 [y])) && isPowerOfTwo32(y) + => (Eq32 (And32 x (Const32 [y])) (Const32 [0])) +(Neq64 (And64 x (Const64 [y])) (Const64 [y])) && isPowerOfTwo64(y) + => (Eq64 (And64 x (Const64 [y])) (Const64 [0])) // Reassociate expressions involving // constants such that constants come first, diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 28b3492c98..5ef9ac5d30 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -6313,7 +6313,7 @@ func rewriteValuegeneric_OpEq16(v *Value) bool { break } // match: (Eq16 (And16 x (Const16 [y])) (Const16 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo16(y) // result: (Neq16 (And16 x (Const16 [y])) (Const16 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -6329,17 +6329,17 @@ func rewriteValuegeneric_OpEq16(v *Value) bool { if v_0_1.Op != OpConst16 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst16 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt16(v_0_1.AuxInt) + if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(isPowerOfTwo16(y)) { continue } v.reset(OpNeq16) v0 := b.NewValue0(v.Pos, OpAnd16, t) v1 := b.NewValue0(v.Pos, OpConst16, t) - v1.AuxInt = y + v1.AuxInt = int16ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst16, t) - v2.AuxInt = 0 + v2.AuxInt = int16ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -7177,7 +7177,7 @@ func rewriteValuegeneric_OpEq32(v *Value) bool { break } // match: (Eq32 (And32 x (Const32 [y])) (Const32 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo32(y) // result: (Neq32 (And32 x (Const32 [y])) (Const32 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -7193,17 +7193,17 @@ func rewriteValuegeneric_OpEq32(v *Value) bool { if v_0_1.Op != OpConst32 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst32 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt32(v_0_1.AuxInt) + if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(isPowerOfTwo32(y)) { continue } v.reset(OpNeq32) v0 := b.NewValue0(v.Pos, OpAnd32, t) v1 := b.NewValue0(v.Pos, OpConst32, t) - v1.AuxInt = y + v1.AuxInt = int32ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst32, t) - v2.AuxInt = 0 + v2.AuxInt = int32ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -7758,7 +7758,7 @@ func rewriteValuegeneric_OpEq64(v *Value) bool { break } // match: (Eq64 (And64 x (Const64 [y])) (Const64 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo64(y) // result: (Neq64 (And64 x (Const64 [y])) (Const64 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -7774,17 +7774,17 @@ func rewriteValuegeneric_OpEq64(v *Value) bool { if v_0_1.Op != OpConst64 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst64 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt64(v_0_1.AuxInt) + if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(isPowerOfTwo64(y)) { continue } v.reset(OpNeq64) v0 := b.NewValue0(v.Pos, OpAnd64, t) v1 := b.NewValue0(v.Pos, OpConst64, t) - v1.AuxInt = y + v1.AuxInt = int64ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst64, t) - v2.AuxInt = 0 + v2.AuxInt = int64ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -8180,7 +8180,7 @@ func rewriteValuegeneric_OpEq8(v *Value) bool { break } // match: (Eq8 (And8 x (Const8 [y])) (Const8 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo8(y) // result: (Neq8 (And8 x (Const8 [y])) (Const8 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -8196,17 +8196,17 @@ func rewriteValuegeneric_OpEq8(v *Value) bool { if v_0_1.Op != OpConst8 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst8 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt8(v_0_1.AuxInt) + if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(isPowerOfTwo8(y)) { continue } v.reset(OpNeq8) v0 := b.NewValue0(v.Pos, OpAnd8, t) v1 := b.NewValue0(v.Pos, OpConst8, t) - v1.AuxInt = y + v1.AuxInt = int8ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst8, t) - v2.AuxInt = 0 + v2.AuxInt = int8ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -14907,7 +14907,7 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { break } // match: (Neq16 (And16 x (Const16 [y])) (Const16 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo16(y) // result: (Eq16 (And16 x (Const16 [y])) (Const16 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -14923,17 +14923,17 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { if v_0_1.Op != OpConst16 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst16 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt16(v_0_1.AuxInt) + if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(isPowerOfTwo16(y)) { continue } v.reset(OpEq16) v0 := b.NewValue0(v.Pos, OpAnd16, t) v1 := b.NewValue0(v.Pos, OpConst16, t) - v1.AuxInt = y + v1.AuxInt = int16ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst16, t) - v2.AuxInt = 0 + v2.AuxInt = int16ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -15094,7 +15094,7 @@ func rewriteValuegeneric_OpNeq32(v *Value) bool { break } // match: (Neq32 (And32 x (Const32 [y])) (Const32 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo32(y) // result: (Eq32 (And32 x (Const32 [y])) (Const32 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15110,17 +15110,17 @@ func rewriteValuegeneric_OpNeq32(v *Value) bool { if v_0_1.Op != OpConst32 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst32 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt32(v_0_1.AuxInt) + if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(isPowerOfTwo32(y)) { continue } v.reset(OpEq32) v0 := b.NewValue0(v.Pos, OpAnd32, t) v1 := b.NewValue0(v.Pos, OpConst32, t) - v1.AuxInt = y + v1.AuxInt = int32ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst32, t) - v2.AuxInt = 0 + v2.AuxInt = int32ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -15304,7 +15304,7 @@ func rewriteValuegeneric_OpNeq64(v *Value) bool { break } // match: (Neq64 (And64 x (Const64 [y])) (Const64 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo64(y) // result: (Eq64 (And64 x (Const64 [y])) (Const64 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15320,17 +15320,17 @@ func rewriteValuegeneric_OpNeq64(v *Value) bool { if v_0_1.Op != OpConst64 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst64 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt64(v_0_1.AuxInt) + if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(isPowerOfTwo64(y)) { continue } v.reset(OpEq64) v0 := b.NewValue0(v.Pos, OpAnd64, t) v1 := b.NewValue0(v.Pos, OpConst64, t) - v1.AuxInt = y + v1.AuxInt = int64ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst64, t) - v2.AuxInt = 0 + v2.AuxInt = int64ToAuxInt(0) v.AddArg2(v0, v2) return true } @@ -15514,7 +15514,7 @@ func rewriteValuegeneric_OpNeq8(v *Value) bool { break } // match: (Neq8 (And8 x (Const8 [y])) (Const8 [y])) - // cond: isPowerOfTwo(y) + // cond: isPowerOfTwo8(y) // result: (Eq8 (And8 x (Const8 [y])) (Const8 [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15530,17 +15530,17 @@ func rewriteValuegeneric_OpNeq8(v *Value) bool { if v_0_1.Op != OpConst8 || v_0_1.Type != t { continue } - y := v_0_1.AuxInt - if v_1.Op != OpConst8 || v_1.Type != t || v_1.AuxInt != y || !(isPowerOfTwo(y)) { + y := auxIntToInt8(v_0_1.AuxInt) + if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(isPowerOfTwo8(y)) { continue } v.reset(OpEq8) v0 := b.NewValue0(v.Pos, OpAnd8, t) v1 := b.NewValue0(v.Pos, OpConst8, t) - v1.AuxInt = y + v1.AuxInt = int8ToAuxInt(y) v0.AddArg2(x, v1) v2 := b.NewValue0(v.Pos, OpConst8, t) - v2.AuxInt = 0 + v2.AuxInt = int8ToAuxInt(0) v.AddArg2(v0, v2) return true } -- 2.50.0