diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-20 14:43:30 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2020-04-21 00:38:34 +0000 |
commit | 50b11318febd74c26cc466cc4557347bcb53181a (patch) | |
tree | 1af35a1788920f922e481f23317091051988db56 /src/cmd/compile/internal/ssa/rewritegeneric.go | |
parent | 12665b9a067789004ca45cedcd3ebbbdc143f1d7 (diff) | |
download | go-50b11318febd74c26cc466cc4557347bcb53181a.tar.gz go-50b11318febd74c26cc466cc4557347bcb53181a.zip |
cmd/compile: use oneBit instead of isPowerOfTwo in bit optimization
This optimization works on any integer with exactly one bit set.
This is identical to being a power of two, except in the
most negative number. Use oneBit instead.
The rule now triggers in a few more places in std+cmd,
in packages encoding/asn1, crypto/elliptic, and
vendor/golang.org/x/crypto/cryptobyte.
This change obviates the need for CL 222479
by doing this optimization consistently in the compiler.
Change-Id: I983c6235290fdc634fda5e11b10f1f8ce041272f
Reviewed-on: https://go-review.googlesource.com/c/go/+/229124
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/rewritegeneric.go')
-rw-r--r-- | src/cmd/compile/internal/ssa/rewritegeneric.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 5ef9ac5d30..1fabe738d4 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 <t> x (Const16 <t> [y])) (Const16 <t> [y])) - // cond: isPowerOfTwo16(y) + // cond: oneBit16(y) // result: (Neq16 (And16 <t> x (Const16 <t> [y])) (Const16 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -6330,7 +6330,7 @@ func rewriteValuegeneric_OpEq16(v *Value) bool { continue } y := auxIntToInt16(v_0_1.AuxInt) - if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(isPowerOfTwo16(y)) { + if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(oneBit16(y)) { continue } v.reset(OpNeq16) @@ -7177,7 +7177,7 @@ func rewriteValuegeneric_OpEq32(v *Value) bool { break } // match: (Eq32 (And32 <t> x (Const32 <t> [y])) (Const32 <t> [y])) - // cond: isPowerOfTwo32(y) + // cond: oneBit32(y) // result: (Neq32 (And32 <t> x (Const32 <t> [y])) (Const32 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -7194,7 +7194,7 @@ func rewriteValuegeneric_OpEq32(v *Value) bool { continue } y := auxIntToInt32(v_0_1.AuxInt) - if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(isPowerOfTwo32(y)) { + if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(oneBit32(y)) { continue } v.reset(OpNeq32) @@ -7758,7 +7758,7 @@ func rewriteValuegeneric_OpEq64(v *Value) bool { break } // match: (Eq64 (And64 <t> x (Const64 <t> [y])) (Const64 <t> [y])) - // cond: isPowerOfTwo64(y) + // cond: oneBit64(y) // result: (Neq64 (And64 <t> x (Const64 <t> [y])) (Const64 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -7775,7 +7775,7 @@ func rewriteValuegeneric_OpEq64(v *Value) bool { continue } y := auxIntToInt64(v_0_1.AuxInt) - if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(isPowerOfTwo64(y)) { + if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(oneBit64(y)) { continue } v.reset(OpNeq64) @@ -8180,7 +8180,7 @@ func rewriteValuegeneric_OpEq8(v *Value) bool { break } // match: (Eq8 (And8 <t> x (Const8 <t> [y])) (Const8 <t> [y])) - // cond: isPowerOfTwo8(y) + // cond: oneBit8(y) // result: (Neq8 (And8 <t> x (Const8 <t> [y])) (Const8 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -8197,7 +8197,7 @@ func rewriteValuegeneric_OpEq8(v *Value) bool { continue } y := auxIntToInt8(v_0_1.AuxInt) - if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(isPowerOfTwo8(y)) { + if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(oneBit8(y)) { continue } v.reset(OpNeq8) @@ -14907,7 +14907,7 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { break } // match: (Neq16 (And16 <t> x (Const16 <t> [y])) (Const16 <t> [y])) - // cond: isPowerOfTwo16(y) + // cond: oneBit16(y) // result: (Eq16 (And16 <t> x (Const16 <t> [y])) (Const16 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -14924,7 +14924,7 @@ func rewriteValuegeneric_OpNeq16(v *Value) bool { continue } y := auxIntToInt16(v_0_1.AuxInt) - if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(isPowerOfTwo16(y)) { + if v_1.Op != OpConst16 || v_1.Type != t || auxIntToInt16(v_1.AuxInt) != y || !(oneBit16(y)) { continue } v.reset(OpEq16) @@ -15094,7 +15094,7 @@ func rewriteValuegeneric_OpNeq32(v *Value) bool { break } // match: (Neq32 (And32 <t> x (Const32 <t> [y])) (Const32 <t> [y])) - // cond: isPowerOfTwo32(y) + // cond: oneBit32(y) // result: (Eq32 (And32 <t> x (Const32 <t> [y])) (Const32 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15111,7 +15111,7 @@ func rewriteValuegeneric_OpNeq32(v *Value) bool { continue } y := auxIntToInt32(v_0_1.AuxInt) - if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(isPowerOfTwo32(y)) { + if v_1.Op != OpConst32 || v_1.Type != t || auxIntToInt32(v_1.AuxInt) != y || !(oneBit32(y)) { continue } v.reset(OpEq32) @@ -15304,7 +15304,7 @@ func rewriteValuegeneric_OpNeq64(v *Value) bool { break } // match: (Neq64 (And64 <t> x (Const64 <t> [y])) (Const64 <t> [y])) - // cond: isPowerOfTwo64(y) + // cond: oneBit64(y) // result: (Eq64 (And64 <t> x (Const64 <t> [y])) (Const64 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15321,7 +15321,7 @@ func rewriteValuegeneric_OpNeq64(v *Value) bool { continue } y := auxIntToInt64(v_0_1.AuxInt) - if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(isPowerOfTwo64(y)) { + if v_1.Op != OpConst64 || v_1.Type != t || auxIntToInt64(v_1.AuxInt) != y || !(oneBit64(y)) { continue } v.reset(OpEq64) @@ -15514,7 +15514,7 @@ func rewriteValuegeneric_OpNeq8(v *Value) bool { break } // match: (Neq8 (And8 <t> x (Const8 <t> [y])) (Const8 <t> [y])) - // cond: isPowerOfTwo8(y) + // cond: oneBit8(y) // result: (Eq8 (And8 <t> x (Const8 <t> [y])) (Const8 <t> [0])) for { for _i0 := 0; _i0 <= 1; _i0, v_0, v_1 = _i0+1, v_1, v_0 { @@ -15531,7 +15531,7 @@ func rewriteValuegeneric_OpNeq8(v *Value) bool { continue } y := auxIntToInt8(v_0_1.AuxInt) - if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(isPowerOfTwo8(y)) { + if v_1.Op != OpConst8 || v_1.Type != t || auxIntToInt8(v_1.AuxInt) != y || !(oneBit8(y)) { continue } v.reset(OpEq8) |