[llvm] [SPIR-V] Lower nested aggregate insertvalue operands (PR #204239)

Tim Besard via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 01:47:00 PDT 2026


================
@@ -2465,6 +2465,17 @@ SPIRVEmitIntrinsicsImpl::visitExtractValueInst(ExtractValueInst &I) {
     Args.push_back(B.getInt32(Op));
   Instruction *NewI = B.CreateIntrinsicWithoutFolding(Intrinsic::spv_extractv,
                                                       {I.getType()}, {Args});
+  // If this aggregate extract feeds another insertvalue, the extracted
+  // composite is used as a SPIR-V value-id by llvm.spv.insertv. Keep the real
+  // aggregate type in metadata, but expose the value itself as i32 so the
+  // intrinsic signature remains valid.
+  if (NewI->getType()->isAggregateType() &&
+      any_of(I.users(), [](User *U) { return isa<InsertValueInst>(U); })) {
----------------
maleadt wrote:

I experimented with this a bit, forcing the pass to visit the insert before the extract. Widening the check does produce the invalid call from my example above, which the verifier then rejects. Interestingly though, there's nothing for the check to fix in that case: when the insert gets lowered, the `spv_insertv` declaration is created based on the type the inserted operand has at that point. Since the extract hasn't been lowered yet, that's still the aggregate type, so the call and declaration already match. In other words, the `i32` mutation only matters for `insertvalues` that haven't been lowered yet, i.e. what the current check catches, so I'd keep it as is.

https://github.com/llvm/llvm-project/pull/204239


More information about the llvm-commits mailing list