]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use isUnsignedPowerOfTwo rather than isPowerOfTwo for unsigneds
authorJorropo <jorropo.pgm@gmail.com>
Thu, 4 Dec 2025 03:17:58 +0000 (04:17 +0100)
committerGopher Robot <gobot@golang.org>
Thu, 4 Dec 2025 16:13:28 +0000 (08:13 -0800)
Fixes #76688

Change-Id: Icb8dab54a5ce7d83b656d50d5ea605d2a62b96f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/726680
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/cmd/compile/internal/ssa/prove.go
test/prove.go

index 1aab7e3eb775e9e9b7eafd13ea06ebe644f9736e..39080a015e938415193c29c40729444d5730a417 100644 (file)
@@ -2885,9 +2885,9 @@ func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
                        xl := ft.limits[x.ID]
                        y := v.Args[1]
                        yl := ft.limits[y.ID]
-                       if xl.umin == xl.umax && isPowerOfTwo(int64(xl.umin)) ||
+                       if xl.umin == xl.umax && isUnsignedPowerOfTwo(xl.umin) ||
                                xl.min == xl.max && isPowerOfTwo(xl.min) ||
-                               yl.umin == yl.umax && isPowerOfTwo(int64(yl.umin)) ||
+                               yl.umin == yl.umax && isUnsignedPowerOfTwo(yl.umin) ||
                                yl.min == yl.max && isPowerOfTwo(yl.min) {
                                // 0,1 * a power of two is better done as a shift
                                break
index 1b50317fe3ea4e5abb4ad09f22e67518de1a123b..e04b510e17001cc8d98f83bdbbdd7e865f6099c7 100644 (file)
@@ -2718,6 +2718,14 @@ func detectStringLenRelation(s string) bool {
        return false
 }
 
+func issue76688(x, y uint64) uint64 {
+       if x > 1 || y != 1<<63 {
+               return 42
+       }
+       // We do not want to rewrite the multiply to a condselect here since opt can do a better job with a left shift.
+       return x * y
+}
+
 //go:noinline
 func prove(x int) {
 }