Skip to content

cmd/compile: incorrect SETcc Jcc mapping could lead to a misscompilation #79873

Closed

Description

@Jorropo

Go version

go version go1.27-devel_d2b991c840 Thu Jun 4 14:28:42 2026 -0700 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='/home/hugo/go/bin'
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-build2718037690=/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'
GOPACKAGESDRIVER=''
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.27-devel_d2b991c840 Thu Jun 4 14:28:42 2026 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Take a look at:

(NE t:(TESTQ x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
(NE t:(TESTL x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
(NE t:(TESTW x:(MOVBQZX s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags)) x) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)
(NE t:(TESTB s:(SET(EQ|NE|L|G|LE|GE|A|B|AE|BE|EQF|NEF|GF|GEF) flags) s) yes no) && t.Block == s.Block => ((EQ|NE|LT|GT|LE|GE|UGT|ULT|UGE|ULE|EQF|NEF|UGE|UGT) flags yes no)

If you take a look at:

(If (SETGF cmp) yes no) => (UGT cmp yes no)
(If (SETGEF cmp) yes no) => (UGE cmp yes no)

What did you see happen?

GF incorrectly map to UGE and GF to UGT.

What did you expect to see?

GF should map to UGT and GEF to UGE.

Activity

  1. added this to the Go1.27 milestone on Jun 6, 2026
  2. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    FixPendingIssues that have a fix which has not yet been reviewed or submitted.
    on Jun 6, 2026
  3. Jorropo commented on Jun 6, 2026

    @Jorropo
    MemberAuthor

    Due to #56722

  4. Jorropo commented on Jun 6, 2026

    @Jorropo
    MemberAuthor

    Adding release blocker since it's a misscompilation we never released and I would like to make sure we merge the fix in 1.27.

  5. Jorropo commented on Jun 6, 2026

    @Jorropo
    MemberAuthor

    I am not sure this rule is reachable, it's pretty tricky since we I've added equivalent rules bool → int → bool removal rules generic.rules, so the simple repros get properly optimized earlier in the passes.

    Anyhow we can't leave them in this broken state.

  6. gopherbot commented on Jun 6, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/786860 mentions this issue: cmd/compile: fix AMD64 misscompilation due to AMD64 SETcc and Jcc mapping

  7. self-assigned this
    on Jun 6, 2026
  8. gabyhelp commented on Jun 6, 2026

    @gabyhelp

    Related Issues

    (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

  9. added a commit that references this issue on Jun 14, 2026
    38e988e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

FixPendingIssues 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.compiler/runtimeIssues related to the Go compiler and/or runtime.release-blocker

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions