Repository navigation
compiler: add early AVX2 SIMD128 multiversioning through Go APIs #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xushiwei
merged 13 commits into
xgo-dev:main
from
zhouguangyuan0718:codex/simd-fmv-20261007
Oct 12, 2026
+1,893
−7
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d982836
compiler: add early AVX2 multiversioning for SIMD128
zhouguangyuan0718 de8f7e1
llvmfmv: discover guarded roots from CPU query uses
zhouguangyuan0718 53ccb76
test: retain failed SIMD binaries and report captured frames
zhouguangyuan0718 c4a83e2
runtime: preserve Windows physical function identity after LTO
zhouguangyuan0718 7309662
compiler: implement SIMD FMV through LLVM Go APIs
zhouguangyuan0718 7f92514
test: cover Go FMV signature and dispatcher ABI boundaries
zhouguangyuan0718 3f0f05d
compiler: align SIMD FMV dispatch and inlining with GoALLC
zhouguangyuan0718 828966d
deps: update LLVM bindings after IR API review
zhouguangyuan0718 67f3c27
deps: use released LLVM bindings v0.10.1
zhouguangyuan0718 62a0365
test: harden FMV baseline and inlining policy checks
zhouguangyuan0718 7c0d7b1
compiler: centralize FMV string identifiers
zhouguangyuan0718 3777463
compiler: preserve COMDAT on SIMD FMV variants
zhouguangyuan0718 2b50ef0
build: lower Win64 vector parameters in C exports
zhouguangyuan0718 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package cl | ||
|
|
||
| import ( | ||
| "go/types" | ||
|
|
||
| "github.com/xgo-dev/llgo/internal/llvmfmv" | ||
| llssa "github.com/xgo-dev/llgo/ssa" | ||
| "golang.org/x/tools/go/ssa" | ||
| ) | ||
|
|
||
| func simdCPUQuery(fn *ssa.Function) string { | ||
| obj, ok := fn.Object().(*types.Func) | ||
| if !ok || obj.Pkg() == nil || obj.Pkg().Path() != "simd/archsimd" || obj.Name() != "AVX2" || | ||
| !types.Identical(obj.Type(), fn.Signature) { | ||
| return "" | ||
| } | ||
| sig := fn.Signature | ||
| if sig.Recv() == nil || sig.Params().Len() != 0 || sig.Results().Len() != 1 || | ||
| !types.Identical(sig.Results().At(0).Type(), types.Typ[types.Bool]) { | ||
| return "" | ||
| } | ||
| recv, ok := sig.Recv().Type().(*types.Named) | ||
| if !ok || recv.Obj().Pkg() != obj.Pkg() || recv.Obj().Name() != "X86Features" { | ||
| return "" | ||
| } | ||
| return llvmfmv.AVX2Query | ||
| } | ||
|
|
||
| func (p *context) markSIMDFMV(fn llssa.Function, source *ssa.Function) { | ||
| if fn == nil || p.prog.Target().GOARCH != "amd64" { | ||
| return | ||
| } | ||
| // Bodyless assembly/linkname declarations do not promise a compiler-emitted | ||
| // entry. Official SIMD intrinsic declarations have LLGo-generated bodies. | ||
| _, intrinsic := lookupSIMD(source, "amd64") | ||
| available := len(source.Blocks) != 0 || intrinsic | ||
| hasVector := false | ||
| sig := source.Signature | ||
| check := func(t types.Type) { | ||
| if _, ok := llssa.SIMDVectorShape(t); ok { | ||
| hasVector = true | ||
| } | ||
| } | ||
| if sig.Recv() != nil { | ||
| check(sig.Recv().Type()) | ||
| } | ||
| for i := 0; i < sig.Params().Len(); i++ { | ||
| check(sig.Params().At(i).Type()) | ||
| } | ||
| for i := 0; i < sig.Results().Len(); i++ { | ||
| check(sig.Results().At(i).Type()) | ||
| } | ||
| fn.MarkSIMDFMV(available && hasVector, simdCPUQuery(source)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
| cd "$(dirname "${BASH_SOURCE[0]}")/.." | ||
|
|
||
| : "${LLGO:=llgo}" | ||
| export GOEXPERIMENT=simd | ||
|
|
||
| if [[ "$(go env GOARCH)" != amd64 ]]; then | ||
| "$LLGO" test -O0 -count=1 -timeout=2m ./test/simd/... | ||
| "$LLGO" test -O2 -count=1 -timeout=2m ./test/simd/... | ||
| exit | ||
| fi | ||
|
|
||
| export GOAMD64=v1 | ||
| if [[ -n "${LLGO_SIMD_ARTIFACT_DIR:-}" ]]; then | ||
| output=$LLGO_SIMD_ARTIFACT_DIR | ||
| mkdir -p "$output" | ||
| else | ||
| output=$(mktemp -d) | ||
| trap 'rm -rf "$output"' EXIT | ||
| fi | ||
|
|
||
| for profile in O0-off O2-off O2-thin O2-full; do | ||
| opt=${profile%%-*} | ||
| lto=${profile#*-} | ||
| flags=("-$opt") | ||
| if [[ "$lto" != off ]]; then | ||
| flags+=("-lto=$lto") | ||
| fi | ||
| echo "SIMD: amd64 $profile" | ||
| binary="$output/simd-$profile.exe" | ||
| "$LLGO" test "${flags[@]}" -c -o "$binary" ./test/simd | ||
| "$binary" -test.v -test.count=1 -test.timeout=2m | ||
| for debug in cpu.avx2=off cpu.avx=off cpu.fma=off cpu.all=off; do | ||
| echo "SIMD FMV: $profile GODEBUG=$debug" | ||
| GODEBUG="$debug" "$binary" -test.v -test.count=1 -test.timeout=2m -test.run='^TestSIMDFMV' | ||
| done | ||
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Apply Win64 vector lowering to C export wrappers too
Package implementations now lower SIMD128 parameters to
ptr, butlowerMainCExportModuleleaves their declarations/calls in the generated export wrappers as vectors:This prevents LTO from inlining even a simple exported
Float32x4addition. Verified with actual Clang bitcode +lld-linkunder both Full and Thin LTO: the current code retains an extra call and parameter stack temporary; applying the same lowering to the wrapper module inlinesaddpsand reduces the example's stack allocation from 72 to 56 bytes.Please also run
LowerWindowsVectorParamsinlowerMainCExportModuleand cover this path. This is a nonblocking optimization issue; I have not found a runtime correctness failure from the mismatch.