Skip to content

cmd/compile: on AMD64 slow instruction sequence to Zext a < register size instruction output #76066

Description

@Jorropo

Go version

go version go1.26-devel_b3e316e269 Sun Oct 26 22:49:49 2025 +0100 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-build2204351525=/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_b3e316e269 Sun Oct 26 22:49:49 2025 +0100'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Compile the f function:

func branchlessBoolToInt(x bool) (r uint) {
 if x { r = 1 }
 return
}

func f(x, y uint) uint {
 return branchlessBoolToInt(x != y)
}

What did you see happen?

        TEXT    command-line-arguments.f(SB), NOSPLIT|NOFRAME|ABIInternal, $0-16
        ... ; metadata
        CMPQ    BX, AX
        SETNE   CL
        MOVBLZX CL, AX
        RET

What did you expect to see?

        TEXT    command-line-arguments.f(SB), NOSPLIT|NOFRAME|ABIInternal, $0-16
        ... ; metadata
        XORL CL, CL
        CMPQ    BX, AX
        SETNE   CL
        RET

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions