Skip to content

Commit 2b622b0

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: remove isUintXPowerOfTwo functions
And use the generic version instead. While at it, also correct the corresponding rules to use logXu variants instead of logXu, following discussion in CL 689815. Change-Id: Iba85d14ff0e26d45a126764e7bd5702586358d23 Reviewed-on: https://go-review.googlesource.com/c/go/+/692917 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 72147ff commit 2b622b0

File tree

3 files changed

+104
-110
lines changed

3 files changed

+104
-110
lines changed

src/cmd/compile/internal/ssa/_gen/AMD64.rules

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -606,31 +606,31 @@
606606
// mutandis, for UGE and SETAE, and CC and SETCC.
607607
((NE|EQ) (TESTL (SHLL (MOVLconst [1]) x) y)) => ((ULT|UGE) (BTL x y))
608608
((NE|EQ) (TESTQ (SHLQ (MOVQconst [1]) x) y)) => ((ULT|UGE) (BTQ x y))
609-
((NE|EQ) (TESTLconst [c] x)) && isUint32PowerOfTwo(int64(c))
610-
=> ((ULT|UGE) (BTLconst [int8(log32(c))] x))
611-
((NE|EQ) (TESTQconst [c] x)) && isUint64PowerOfTwo(int64(c))
612-
=> ((ULT|UGE) (BTQconst [int8(log32(c))] x))
613-
((NE|EQ) (TESTQ (MOVQconst [c]) x)) && isUint64PowerOfTwo(c)
614-
=> ((ULT|UGE) (BTQconst [int8(log64(c))] x))
609+
((NE|EQ) (TESTLconst [c] x)) && isUnsignedPowerOfTwo(uint32(c))
610+
=> ((ULT|UGE) (BTLconst [int8(log32u(uint32(c)))] x))
611+
((NE|EQ) (TESTQconst [c] x)) && isUnsignedPowerOfTwo(uint64(c))
612+
=> ((ULT|UGE) (BTQconst [int8(log32u(uint32(c)))] x))
613+
((NE|EQ) (TESTQ (MOVQconst [c]) x)) && isUnsignedPowerOfTwo(uint64(c))
614+
=> ((ULT|UGE) (BTQconst [int8(log64u(uint64(c)))] x))
615615
(SET(NE|EQ) (TESTL (SHLL (MOVLconst [1]) x) y)) => (SET(B|AE) (BTL x y))
616616
(SET(NE|EQ) (TESTQ (SHLQ (MOVQconst [1]) x) y)) => (SET(B|AE) (BTQ x y))
617-
(SET(NE|EQ) (TESTLconst [c] x)) && isUint32PowerOfTwo(int64(c))
618-
=> (SET(B|AE) (BTLconst [int8(log32(c))] x))
619-
(SET(NE|EQ) (TESTQconst [c] x)) && isUint64PowerOfTwo(int64(c))
620-
=> (SET(B|AE) (BTQconst [int8(log32(c))] x))
621-
(SET(NE|EQ) (TESTQ (MOVQconst [c]) x)) && isUint64PowerOfTwo(c)
622-
=> (SET(B|AE) (BTQconst [int8(log64(c))] x))
617+
(SET(NE|EQ) (TESTLconst [c] x)) && isUnsignedPowerOfTwo(uint32(c))
618+
=> (SET(B|AE) (BTLconst [int8(log32u(uint32(c)))] x))
619+
(SET(NE|EQ) (TESTQconst [c] x)) && isUnsignedPowerOfTwo(uint64(c))
620+
=> (SET(B|AE) (BTQconst [int8(log32u(uint32(c)))] x))
621+
(SET(NE|EQ) (TESTQ (MOVQconst [c]) x)) && isUnsignedPowerOfTwo(uint64(c))
622+
=> (SET(B|AE) (BTQconst [int8(log64u(uint64(c)))] x))
623623
// SET..store variant
624624
(SET(NE|EQ)store [off] {sym} ptr (TESTL (SHLL (MOVLconst [1]) x) y) mem)
625625
=> (SET(B|AE)store [off] {sym} ptr (BTL x y) mem)
626626
(SET(NE|EQ)store [off] {sym} ptr (TESTQ (SHLQ (MOVQconst [1]) x) y) mem)
627627
=> (SET(B|AE)store [off] {sym} ptr (BTQ x y) mem)
628-
(SET(NE|EQ)store [off] {sym} ptr (TESTLconst [c] x) mem) && isUint32PowerOfTwo(int64(c))
629-
=> (SET(B|AE)store [off] {sym} ptr (BTLconst [int8(log32(c))] x) mem)
630-
(SET(NE|EQ)store [off] {sym} ptr (TESTQconst [c] x) mem) && isUint64PowerOfTwo(int64(c))
631-
=> (SET(B|AE)store [off] {sym} ptr (BTQconst [int8(log32(c))] x) mem)
632-
(SET(NE|EQ)store [off] {sym} ptr (TESTQ (MOVQconst [c]) x) mem) && isUint64PowerOfTwo(c)
633-
=> (SET(B|AE)store [off] {sym} ptr (BTQconst [int8(log64(c))] x) mem)
628+
(SET(NE|EQ)store [off] {sym} ptr (TESTLconst [c] x) mem) && isUnsignedPowerOfTwo(uint32(c))
629+
=> (SET(B|AE)store [off] {sym} ptr (BTLconst [int8(log32u(uint32(c)))] x) mem)
630+
(SET(NE|EQ)store [off] {sym} ptr (TESTQconst [c] x) mem) && isUnsignedPowerOfTwo(uint64(c))
631+
=> (SET(B|AE)store [off] {sym} ptr (BTQconst [int8(log32u(uint32(c)))] x) mem)
632+
(SET(NE|EQ)store [off] {sym} ptr (TESTQ (MOVQconst [c]) x) mem) && isUnsignedPowerOfTwo(uint64(c))
633+
=> (SET(B|AE)store [off] {sym} ptr (BTQconst [int8(log64u(uint64(c)))] x) mem)
634634

635635
// Handle bit-testing in the form (a>>b)&1 != 0 by building the above rules
636636
// and further combining shifts.
@@ -655,14 +655,14 @@
655655
(XOR(Q|L) (SHL(Q|L) (MOV(Q|L)const [1]) y) x) => (BTC(Q|L) x y)
656656
// Note: only convert OR/XOR to BTS/BTC if the constant wouldn't fit in
657657
// the constant field of the OR/XOR instruction. See issue 61694.
658-
((OR|XOR)Q (MOVQconst [c]) x) && isUint64PowerOfTwo(c) && uint64(c) >= 1<<31 => (BT(S|C)Qconst [int8(log64(c))] x)
658+
((OR|XOR)Q (MOVQconst [c]) x) && isUnsignedPowerOfTwo(uint64(c)) && uint64(c) >= 1<<31 => (BT(S|C)Qconst [int8(log64u(uint64(c)))] x)
659659

660660
// Recognize bit clearing: a &^= 1<<b
661661
(AND(Q|L) (NOT(Q|L) (SHL(Q|L) (MOV(Q|L)const [1]) y)) x) => (BTR(Q|L) x y)
662662
(ANDN(Q|L) x (SHL(Q|L) (MOV(Q|L)const [1]) y)) => (BTR(Q|L) x y)
663663
// Note: only convert AND to BTR if the constant wouldn't fit in
664664
// the constant field of the AND instruction. See issue 61694.
665-
(ANDQ (MOVQconst [c]) x) && isUint64PowerOfTwo(^c) && uint64(^c) >= 1<<31 => (BTRQconst [int8(log64(^c))] x)
665+
(ANDQ (MOVQconst [c]) x) && isUnsignedPowerOfTwo(uint64(^c)) && uint64(^c) >= 1<<31 => (BTRQconst [int8(log64u(uint64(^c)))] x)
666666

667667
// Special-case bit patterns on first/last bit.
668668
// generic.rules changes ANDs of high-part/low-part masks into a couple of shifts,

src/cmd/compile/internal/ssa/rewrite.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,6 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool {
504504
return n != 0 && n&(n-1) == 0
505505
}
506506

507-
// isUint64PowerOfTwo reports whether uint64(n) is a power of 2.
508-
func isUint64PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint64(in)) }
509-
510-
// isUint32PowerOfTwo reports whether uint32(n) is a power of 2.
511-
func isUint32PowerOfTwo(in int64) bool { return isUnsignedPowerOfTwo(uint32(in)) }
512-
513507
// is32Bit reports whether n can be represented as a signed 32 bit integer.
514508
func is32Bit(n int64) bool {
515509
return n == int64(int32(n))

0 commit comments

Comments
 (0)