Skip to content

Support multiple indices in OpCompositeExtract and OpCompositeInsert - #1

Merged
maleadt merged 2 commits into
mainfrom
tb/composite-indices
Sep 26, 2026
Merged

maleadt merged 2 commits into
mainfrom
tb/composite-indices

Conversation

@maleadt

@maleadt maleadt commented Sep 26, 2026

Copy link
Copy Markdown
Member

LLVM emits OpCompositeInsert/OpCompositeExtract with several indices for insertvalue/extractvalue with a multi-level index list, e.g. when building a struct that contains a tuple:

%129 = OpCompositeInsert %_struct_58 %123 %128 1 0

OpCompositeInsert rejected these with UNIMPLEMENTED OpCompositeInsert with multiple indices. OpCompositeExtract was worse: it silently used only the first index and read the wrong member. Both now follow every index through struct members, (struct-wrapped) array elements and vector components, rendering e.g. v.m1.m1.e[1].s3.

The member path gives us the leaf type, so a second commit also fixes extracting a pointer member. Pointer leaves are stored as ulong and OpCompositeInsert already casts to that on the way in, but OpCompositeExtract never cast back, producing an integer-to-pointer conversion that OpenCL C compilers reject.

Both are covered by new lit tests (composite_multiple_indices.spt, composite_extract_pointer_leaf.spt). The first came up in JuliaGPU/OpenCL.jl#504, whose new nested aggregates test fails on every source-mode (PoCL-C, NVIDIA) CI job. With this branch, OpenCL.jl's full poclc test suite passes.

LLVM emits these for insertvalue/extractvalue with a multi-level index list,
e.g. when building a struct that contains a tuple. OpCompositeInsert rejected
them, while OpCompositeExtract silently used only the first index and read the
wrong member. Follow every index to render the full member path instead.
Pointer leaves of aggregates are stored as integers, and OpCompositeInsert
casts pointers to that integer type on the way in. OpCompositeExtract didn't
cast back, so extracting a pointer member produced an integer-to-pointer
conversion that OpenCL C compilers reject.
@maleadt
maleadt force-pushed the tb/composite-indices branch from 671853b to bff3713 Compare September 26, 2026 10:05
@maleadt
maleadt merged commit 6a03262 into main Sep 26, 2026
5 checks passed
@maleadt
maleadt deleted the tb/composite-indices branch September 26, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant