Skip to content

SPIR-V: declare native integer widths in the datalayout - #1027

Merged
maleadt merged 2 commits into
mainfrom
tb/spirv-native-ints
Oct 25, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/spirv-native-ints

Conversation

@maleadt

@maleadt maleadt commented Oct 19, 2026

Copy link
Copy Markdown
Member

The SPIR-V datalayout declared no native integer widths, so LLVM treated no width as legal and InstCombine narrowed values to arbitrary widths: a switch on x & 3 became a switch i2, and x^x on 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 the x^x cells 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 a switch_to_lookup key to optimization_options(job) and disables it for SPIR-V. Lookup tables were never formed for SPIR-V before, since fitsInLegalInteger was always false.

The datalayout change was tested on a TGL GPU with oneAPI.jl's execution and device/codegen tests, 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.

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
maleadt force-pushed the tb/spirv-native-ints branch from b00485a to a18797b Compare October 25, 2026 06:17
@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.37%. Comparing base (6602197) to head (a18797b).
⚠️ Report is 7 commits behind head on main.

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.
📢 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 ed5ff41 into main Oct 25, 2026
36 checks passed
@maleadt
maleadt deleted the tb/spirv-native-ints branch October 25, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spirv Stuff about the SPIR-V back-end.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant