From a4fda8d32ac30b787cf2c648daed7f8fe5ef859d Mon Sep 17 00:00:00 2001 From: Jorropo Date: Sun, 7 Dec 2025 03:01:17 +0100 Subject: [PATCH] cmd/compile: improve Ctz's limits modeling and add bruteforce tests This make Ctz perfect within the limitations limits can represent. Change-Id: I1e596d8d01892d1b70031cf03cecc487ce147b38 Reviewed-on: https://go-review.googlesource.com/c/go/+/727780 Reviewed-by: Keith Randall Reviewed-by: Carlos Amedee Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Auto-Submit: Jorropo --- src/cmd/compile/internal/ssa/prove.go | 48 +++++++++++++--------- src/cmd/compile/internal/ssa/prove_test.go | 23 ++++++----- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index 93443a3d3cb..22de2dc7a55 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -269,6 +269,13 @@ func convertIntWithBitsize[Target uint64 | int64, Source uint64 | int64](x Sourc } } +func (l limit) unsignedFixedLeadingBits() (fixed uint64, count uint) { + varying := uint(bits.Len64(l.umin ^ l.umax)) + count = uint(bits.LeadingZeros64(l.umin ^ l.umax)) + fixed = l.umin &^ (1<