From 3bd8c78575a27ee9ac7b3c8d8c35db1feee31737 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 26 Mar 2022 10:36:10 -0700 Subject: [PATCH] cmd/compile: upgrade prove pass to know results of math/bits ops are nonnegative Fixes #51963 Change-Id: Ib9e0521222e6fc41e787f3150b254e058a19addc Reviewed-on: https://go-review.googlesource.com/c/go/+/396036 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Jakub Ciolek Reviewed-by: David Chase Reviewed-by: Eric Fang --- src/cmd/compile/internal/ssa/prove.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index b203584c6b..98af586cab 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -824,6 +824,9 @@ func prove(f *Func) { } lensVars[b] = append(lensVars[b], v) } + case OpCtz64, OpCtz32, OpCtz16, OpCtz8, OpBitLen64, OpBitLen32, OpBitLen16, OpBitLen8: + ft.update(b, v, ft.zero, signed, gt|eq) + // TODO: we could also do <= 64/32/16/8, if that helped. } } } @@ -1372,7 +1375,9 @@ func isNonNegative(v *Value) bool { case OpStringLen, OpSliceLen, OpSliceCap, OpZeroExt8to64, OpZeroExt16to64, OpZeroExt32to64, OpZeroExt8to32, OpZeroExt16to32, OpZeroExt8to16, - OpCtz64, OpCtz32, OpCtz16, OpCtz8: + OpCtz64, OpCtz32, OpCtz16, OpCtz8, + OpCtz64NonZero, OpCtz32NonZero, OpCtz16NonZero, OpCtz8NonZero, + OpBitLen64, OpBitLen32, OpBitLen16, OpBitLen8: return true case OpRsh64Ux64, OpRsh32Ux64: -- 2.50.0