Repository navigation
Closed
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
Go version
go version go1.26-devel_f22d37d574 Mon Dec 1 14:59:40 2025 -0800 linux/amd64
Output of go env in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/tmp/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/hugo/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build310673283=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/hugo/k/go/src/go.mod'
GOMODCACHE='/home/hugo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/hugo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/hugo/k/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/hugo/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/hugo/k/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26-devel_f22d37d574 Mon Dec 1 14:59:40 2025 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'What did you do?
Compile this code
package a
func f(x, y uint64) uint64 {
if x > 1 || y != 1<<63 {
return 42
}
return x * y
}with go build -gcflags=-d=ssa/prove/debug=1 a.go
What did you see happen?
Rewrote Mul v21 into CondSelect; v7 is bool
What did you expect to see?
Nothing, theses lines of code:
go/src/cmd/compile/internal/ssa/prove.go
Lines 2888 to 2894 in 2b62144
| if xl.umin == xl.umax && isPowerOfTwo(int64(xl.umin)) || | |
| xl.min == xl.max && isPowerOfTwo(xl.min) || | |
| yl.umin == yl.umax && isPowerOfTwo(int64(yl.umin)) || | |
| yl.min == yl.max && isPowerOfTwo(yl.min) { | |
| // 0,1 * a power of two is better done as a shift | |
| break | |
| } |
are supposed to prevent rewriting multiplies to condselect for constant powers of two since opt should translate them to a left shift after prove does constant argument folding from limits.
However it uses a signed test for unsigned numbers which gives an incorrect result for 1 << (bitsize-1).
Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.Issues that have a fix which has not yet been reviewed or submitted.NeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Activity
[-]cmd/compile:[/-][+]cmd/compile: prove uses signed `isPowerOfTwo` for testing unsigned constants[/+]gopherbot commentedon Dec 4, 2025
Change https://go.dev/cl/726680 mentions this issue:
cmd/compile: use isUnsignedPowerOfTwo rather than isPowerOfTwo for unsignedsgabyhelp commentedon Dec 4, 2025
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cmd/compile: use isUnsignedPowerOfTwo rather than isPowerOfTwo for un…