Skip to content

Metal: stop legalizing intrinsics that front-ends emit - #1047

Merged
maleadt merged 1 commit into
mainfrom
tb/metal-own-intrinsics
Oct 21, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/metal-own-intrinsics

Conversation

@maleadt

@maleadt maleadt commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

GPUCompiler legalized two families of intrinsics that front-ends emit directly: legalize_barrier_abi! rewrote Metal.jl's barriers for the target AIR and MSL versions (#1020), and legalize_atomic_abi! rewrote air.atomic.* calls emitted in their MSL 4.1 form. That makes GPUCompiler track the intrinsic forms of every front-end release it may be paired with. Like LLVM's back-ends, it should only legalize what it emits itself, and leave the choice of form for the target to the front-end that emits it.

  • Barriers move to Metal.jl (Legalize barriers for the target AIR version here, not in GPUCompiler Metal.jl#1099), so legalize_barrier_abi! is removed.
  • No front-end emits air.atomic.* calls for GPUCompiler to legalize anymore: Metal.jl's atomics are LLVM atomics that lower_atomics! selects, and released Metal.jl versions rewrite their own atomic intrinsics in finish_ir!. What remains of legalize_atomic_abi! is the pointer element type metadata for the downgrader, now annotate_atomic_eltypes!.

Compatibility: Metal.jl main needs JuliaGPU/Metal.jl#1099 to be merged before this is released. No released Metal.jl emits the AIR 2.9 barrier form: Metal ≤ 1.11.1 emits 2-operand barriers, which legalize_barrier_abi! upgraded to the 3-operand form on AIR 2.9 only for conformance with Apple's metal-opt. The GPU accepts them, as it did before GPUCompiler 2.15.1, so those versions keep working without a compat change.

GPUCompiler's Metal tests pass on Julia 1.10 and 1.13, and Metal.jl's synchronization, simd and atomics tests pass against this with Metal.jl#1099.

`legalize_barrier_abi!` rewrote the barriers Metal.jl emits for the target
AIR and MSL versions, and `legalize_atomic_abi!` did the same for
`air.atomic.*` calls in their MSL 4.1 form. That makes GPUCompiler track
the intrinsic forms of every front-end release it may be paired with.
Metal.jl now does this next to the code that emits them (and no longer
emits atomic intrinsics directly), so only legalize what is emitted here:
the atomics and fences this package selects. What remains of
`legalize_atomic_abi!` is the pointer element type metadata for the
downgrader.
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.34%. Comparing base (ba243ce) to head (9df1f59).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1047      +/-   ##
==========================================
- Coverage   92.49%   91.34%   -1.15%     
==========================================
  Files          31       31              
  Lines        7341     7257      -84     
==========================================
- Hits         6790     6629     -161     
- Misses        551      628      +77     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt
maleadt merged commit 4939c9d into main Oct 21, 2026
32 of 36 checks passed
@maleadt
maleadt deleted the tb/metal-own-intrinsics branch October 21, 2026 19:40
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