Repository navigation
Legalize odd-width integers for Metal - #1078
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1078 +/- ##
==========================================
- Coverage 92.65% 91.78% -0.87%
==========================================
Files 31 31
Lines 7501 7693 +192
==========================================
+ Hits 6950 7061 +111
- Misses 551 632 +81 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The AGX back-end cannot handle integers wider than a byte whose width is
not a power of two. Underaligned loads of them and most arithmetic on
them crash the compiler, and naturally-aligned stores are widened to the
next power of two, silently overwriting the bytes after the value. SROA
introduces such integers when it splits or widens an aggregate, e.g. to
copy the padding of `{i32, i8}` as an `i24` (Metal.jl#1125).
Promote these values to the next power of two late in the AIR lowering,
as SelectionDAG's type legalizer does for other back-ends, and split
their loads and stores into power-of-two pieces.
maleadt
force-pushed
the
tb/odd-width-integers
branch
from
November 5, 2026 11:47
be95a1e to
e962900
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Apple's AGX back-end cannot handle integers wider than a byte whose width is not a power of two (JuliaGPU/Metal.jl#1125). Tested on an M1 with macOS 27:
i12throughi96atalign 1), andi72accesses crash at any alignment;store i24 ..., align 4writes 4 bytes,store i56 ..., align 8writes 8;i40–i56values crashes, unless it is azextthat the back-end folds into a naturally-aligned load.SROA introduces these integers when it splits or widens an aggregate. For example, it copies the padding of
{i32, i8}as ani24(the cause of the Julia 1.10 failures in JuliaGPU/AcceleratedKernels.jl#194), and it assembles a 7-byte alloca in ani56.This PR adds
legalize_odd_width_integers!, which does what SelectionDAG's type legalizer does for other back-ends:The pass runs late in
lower_air!, because InstCombine narrows the promoted operations back to odd widths.Validation: the Metal tests pass on 1.10 and 1.13. A device testset covering loads, stores, copies, extensions and arithmetic for
i12toi96passes 42/42 on 1.10 and 1.13; without this PR, it has 20 compiler crashes and 6 wrong results. That test goes into a Metal.jl PR once this is released.