From 644b984027d11d43881507a938b28ed9df3b3320 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Mon, 10 Mar 2025 06:44:38 +0100 Subject: [PATCH] cmd/compile: compute bitsize from type size in prove to clean some switches Change-Id: I215adda9050d214576433700aed4c371a36aaaed Reviewed-on: https://go-review.googlesource.com/c/go/+/656335 Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: David Chase Reviewed-by: Keith Randall Auto-Submit: Jorropo --- src/cmd/compile/internal/ssa/prove.go | 96 ++++++--------------------- 1 file changed, 19 insertions(+), 77 deletions(-) diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index 1b5989e6e5..acbba2b27a 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -1601,19 +1601,8 @@ func initLimit(v *Value) limit { } // Default limits based on type. - var lim limit - switch v.Type.Size() { - case 8: - lim = limit{min: math.MinInt64, max: math.MaxInt64, umin: 0, umax: math.MaxUint64} - case 4: - lim = limit{min: math.MinInt32, max: math.MaxInt32, umin: 0, umax: math.MaxUint32} - case 2: - lim = limit{min: math.MinInt16, max: math.MaxInt16, umin: 0, umax: math.MaxUint16} - case 1: - lim = limit{min: math.MinInt8, max: math.MaxInt8, umin: 0, umax: math.MaxUint8} - default: - panic("bad") - } + bitsize := v.Type.Size() * 8 + lim := limit{min: -(1 << (bitsize - 1)), max: 1<<(bitsize-1) - 1, umin: 0, umax: 1<