Repository navigation
SPIR-V: declare native integer widths in the datalayout - #1027
Merged
Merged
Conversation
This was referenced Oct 21, 2026
maleadt
force-pushed
the
tb/spirv-native-ints
branch
from
October 24, 2026 07:33
1aebd78 to
b00485a
Compare
SimplifyCFG's switch-to-lookup conversion can pack a table into a bitmap, an integer of the table's bit size (e.g. i24), which the Khronos translator does not support. It currently never fires for SPIR-V because the datalayout declares no legal integer widths; disable it explicitly so that adding them does not start producing these bitmaps.
Without an `n` spec LLVM treats no integer width as legal, so InstCombine narrows values to arbitrary widths: a `switch` on `x & 3` becomes a `switch i2`, and `x^x` on complex numbers produces an i63. The Khronos translator does not support these (and crashes on them when used as a library). Add `n8:16:32:64`, as used by the LLVM SPIR-V back-end and DPC++. Fixes JuliaGPU/oneAPI.jl#172.
maleadt
force-pushed
the
tb/spirv-native-ints
branch
from
October 25, 2026 06:17
b00485a to
a18797b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1027 +/- ##
==========================================
- Coverage 92.40% 92.37% -0.03%
==========================================
Files 31 31
Lines 7254 7265 +11
==========================================
+ Hits 6703 6711 +8
- Misses 551 554 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The SPIR-V datalayout declared no native integer widths, so LLVM treated no width as legal and InstCombine narrowed values to arbitrary widths: a
switchonx & 3became aswitch i2, andx^xon complex numbers produced an i63. The Khronos translator doesn't support these, and as a library it segfaults on them (JuliaGPU/oneAPI.jl#172; oneAPI.jl currently skips thex^xcells under LTS for this reason).This adds
n8:16:32:64, as used by LLVM's own SPIR-V layouts and DPC++. Declaring legal widths also enables SimplifyCFG's switch-to-lookup conversion, which packs tables into bitmaps of the table's bit size (e.g.i24); the translator crashes on those too. So the first commit adds aswitch_to_lookupkey tooptimization_options(job)and disables it for SPIR-V. Lookup tables were never formed for SPIR-V before, sincefitsInLegalIntegerwas always false.The datalayout change was tested on a TGL GPU with oneAPI.jl's
executionanddevice/codegentests, under both the LLVM back-end and the LTS translator path.The LLVM SPIR-V back-end compiles these switches correctly, but it miscompiles some other odd-width integer arithmetic. That's a separate upstream issue.