From 26da1199ebdddeebc5eebdd562d8a40f01f42a1b Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Mon, 4 Aug 2025 18:48:43 +0700 Subject: [PATCH] cmd/compile: make isUint{32,64}PowerOfTwo implementations clearer Since these functions cast the input to uint64, so the result always non-negative. The condition should be changed to comparing with zero, thus maaking it clearer to reader, and open room for simplifying in the future by using the generic isUnsignedPowerOfTwo function. Separated this change, so it's easier to do bisecting if there's any problems happened. Change-Id: Ibec28c2590f4c52caa36384b710d526459725e49 Reviewed-on: https://go-review.googlesource.com/c/go/+/692915 Reviewed-by: Dmitri Shuralyov Auto-Submit: Cuong Manh Le Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/rewrite.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index f9a35deecc..5edcc86a42 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -507,13 +507,13 @@ func isUnsignedPowerOfTwo[T uint8 | uint16 | uint32 | uint64](n T) bool { // isUint64PowerOfTwo reports whether uint64(n) is a power of 2. func isUint64PowerOfTwo(in int64) bool { n := uint64(in) - return n > 0 && n&(n-1) == 0 + return n != 0 && n&(n-1) == 0 } // isUint32PowerOfTwo reports whether uint32(n) is a power of 2. func isUint32PowerOfTwo(in int64) bool { n := uint64(uint32(in)) - return n > 0 && n&(n-1) == 0 + return n != 0 && n&(n-1) == 0 } // is32Bit reports whether n can be represented as a signed 32 bit integer. -- 2.51.0