Flatten nested insertvalues for Intel's SPIR-V driver - #953
Merged
Merged
Conversation
Intel's graphics compiler silently drops the store of a field when legalizing an aggregate that was built by a chain of insertvalues, if a later one in the chain has more indices. Add a `driver` field to SPIRVCompilerTarget so that consumers can identify the driver, and flatten nested insertvalues when it is `:intel`.
This was referenced Sep 25, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #953 +/- ##
==========================================
+ Coverage 86.41% 86.46% +0.05%
==========================================
Files 29 29
Lines 5674 5703 +29
==========================================
+ Hits 4903 4931 +28
- Misses 771 772 +1 ☔ 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.
Intel's graphics compiler (IGC) miscompiles aggregates built by nested
insertvaluechains. ItsTypesLegalizationPasssplits aggregate stores into per-field stores by looking up each field in the chain. That lookup gives up on aninsertvaluewith more indices than the field it's looking for, so the store of that field is silently dropped. Aggregate phis are hit as well, because IGC lowers them to stores into an alloca.For example, storing
FlagFirst(flag, (a, b)), withstruct FlagFirst; valid::Bool; value::Tuple{Float32,Int32}; end, losesflag. That breaks e.g.findmin-style reductions over(Bool, value)tuples. See JuliaGPU/OpenCL.jl#502, JuliaGPU/oneAPI.jl#259, and intel/intel-graphics-compiler#378. The bug has been in IGC since 2018 and is still on its master branch.This PR adds a
driverfield toSPIRVCompilerTarget, so that consumers can say which driver will consume the SPIR-V. It defaults to:generic. When the driver is:intel,finish_ir!flattens multi-indexinsertvalues into single-index extract/insert pairs, which IGC handles correctly. The pass has to run after optimization, because InstCombine folds the pairs back together.oneAPI.jl carries its own copy of this pass (from JuliaGPU/oneAPI.jl#548). It could pass
driver=:inteland drop that copy.The change is non-breaking:
driveris a keyword argument with a default, and nothing changes unless a caller passes:intel. The@kwdef-generated positional constructor does gain an argument, but I'm not aware of anyone using it.Tested on an Iris Xe (NEO 26.18, IGC 2.34) with OpenCL.jl passing
driver=:intel. Without this change, the issue's reproducer, a nested struct, a loop-carried aggregate and oneAPI.jl#259'smapreduceall return wrong results. With it, they are all correct.Fixes JuliaGPU/OpenCL.jl#502