Skip to content

cmd/compile: use typed goret for stack ABI results - #139

Open
zhouguangyuan0718 wants to merge 7 commits into
go1.27.masterfrom
codex/llvm-goret-go-verify
Open

cmd/compile: use typed goret for stack ABI results#139
zhouguangyuan0718 wants to merge 7 commits into
go1.27.masterfrom
codex/llvm-goret-go-verify

Conversation

@zhouguangyuan0718

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 18, 2026

Copy link
Copy Markdown

Summary

  • use the Go ABI allocator as the source of truth for results: register-assigned results remain direct LLVM returns, while each non-empty stack-assigned result becomes a typed, aligned goret pointer parameter with "goretindex"="N"
  • allocate caller-owned homes for memory results and use the same home for ordinary SelectN, SelectNAddr, direct calls, indirect/closure calls, and tail-return adaptation
  • bind non-escaping named stack results directly to their goret home, eliminating the callee alloca and final self-copy
  • retain Go escape semantics for heap-escaped named results: mutate one heap object inside the callee, then copy its final value into the goret home at return
  • preserve goret through Go statepoint validation and treat the fixed result home like existing alloca/byval fixed objects during relocation repair
  • rewrite statepoints after standard codegen IR preparation and immediately before SelectionDAG, then split every statepoint continuation
  • rematerialize direct alloca-derived memory addresses in their continuation blocks so SelectionDAG cannot CSE a stale stack address across a growing call
  • update ABI0, cgo unsafe-args, linkname wrappers, deferred named results, GoObj/stack-map fixtures, and statepoint CFG expectations for the new contracts

This change intentionally establishes the result ABI first. Caller result homes are still ordinary entry allocas; forwarding or otherwise eliding those homes is a separate optimization and is not required for correctness.

Validation

  • native Darwin/arm64 standard Go toolchain build against the coordinated static LLVM development payload
  • cmd/compile/internal/ssa: pass
  • statepoint plugin CTest, including focused IR/MIR continuation and direct alloca-memory checks: 97/97 pass
  • ABI differential test: pass through raw IR, O2/statepoint rewrite, MIR, GoObj, pointer maps, and PCSP
  • changed LLVM codegen FileCheck fixtures: 4/4 pass
  • full ABI fixture built with LLVM O2, linked, and executed successfully on native arm64
  • heap-escaped named memory result regression verifies both in-function aliasing and independence of the returned value after the escaped heap object is mutated post-return
  • archive/tar passes with -gcflags=all=-enablellvm\ -llvmironly and default<O2>; TestReadTruncation also passes for 10 consecutive runs

Joint linux-amd64/linux-arm64 CI selects the immutable payload produced from the exact LLVM PR head below.

LLVM-PR: goallc/llvm-project#88

Additional standard-library qualification after LLVM GoObj relocated-private-constant support:

  • Darwin/arm64 O2 dependency-closure tests pass for compress/flate, compress/gzip, compress/zlib, and archive/zip
  • the four packages move from the common blacklist to the common whitelist
  • stdlib policy uses one -gcflags=all=-enablellvm\ -llvmironly flag per test invocation; dependency enumeration and per-package flag expansion were removed after direct all-LLVM flate and runtime entry tests passed

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/llvm-goret-go-verify branch from 793695c to af536c9 Compare August 20, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant