]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: upgrade prove pass to know results of math/bits ops are nonnegative
authorKeith Randall <khr@golang.org>
Sat, 26 Mar 2022 17:36:10 +0000 (10:36 -0700)
committerKeith Randall <khr@golang.org>
Sun, 27 Mar 2022 17:03:16 +0000 (17:03 +0000)
Fixes #51963

Change-Id: Ib9e0521222e6fc41e787f3150b254e058a19addc
Reviewed-on: https://go-review.googlesource.com/c/go/+/396036
Trust: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jakub Ciolek <jakub@ciolek.dev>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Eric Fang <eric.fang@arm.com>
src/cmd/compile/internal/ssa/prove.go

index b203584c6b42cfae2b90d7ef06945900b1982722..98af586cab0dbf98464648550a28c19d3c1c4743 100644 (file)
@@ -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: