From 6e7b9423ad72714f72300a7c479da86624ae7eed Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 3 Nov 2026 14:12:35 +0100 Subject: [PATCH] Check that flattened insertvalues reach the SPIR-V back end The comment on `flatten_nested_insertvalue!` said it has to run after optimization because InstCombine folds the flattened sequences back together. InstCombine also runs after `finish_ir!`, in `prepare_execution!`, so that would undo the Intel workaround. It doesn't: InstCombine never merges single-index `insertvalue`s into multi-index ones, and it is SROA, during optimization, that introduces those. Correct the comment, and test the SPIR-V instead of only the `finish_ir!` output, so that a pass added later between the two can't undo the workaround unnoticed. --- src/spirv.jl | 4 +++- test/spirv.jl | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/spirv.jl b/src/spirv.jl index b5156f47..1e1912eb 100644 --- a/src/spirv.jl +++ b/src/spirv.jl @@ -937,7 +937,9 @@ end # indices than the field it is looking for, silently dropping the store of that field. # e.g., storing `(flag::Bool, (a, b))` built by inserting `flag`, `a` and `b`, loses `flag` # (intel/intel-graphics-compiler#378, JuliaGPU/OpenCL.jl#502, JuliaGPU/oneAPI.jl#259). -# this needs to run after optimization, as InstCombine folds these sequences back together. +# this runs after optimization, where SROA introduces these `insertvalue`s when splitting +# aggregate loads. the InstCombine run in `prepare_execution!` doesn't reconstruct them +# from the flattened form. function flatten_nested_insertvalue!(mod::LLVM.Module) changed = false @tracepoint "flatten nested insertvalue" begin diff --git a/test/spirv.jl b/test/spirv.jl index 35e09f0e..61e24dd5 100644 --- a/test/spirv.jl +++ b/test/spirv.jl @@ -286,6 +286,14 @@ end @check "insertvalue {{.*}}, 1" SPIRV.code_llvm(mod.kernel, tt; backend, driver=:intel) end + + # the flattened form must survive the passes that run between `finish_ir!` and the + # back end (`prepare_execution!` runs InstCombine) + @test @filecheck begin + @check "OpFunction" + @check_not "OpCompositeInsert {{.*}} {{[0-9]+}} {{[0-9]+}}{{\$}}" + SPIRV.code_native(mod.kernel, tt; backend, driver=:intel) + end end ############################################################################################