[llvm] [SPIR-V] Fix crash on direct aggregate return of an intrinsic call result (PR #206491)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 00:56:49 PDT 2026


================
@@ -2679,6 +2680,36 @@ Value *SPIRVEmitIntrinsics::buildSpvUndefComposite(Type *AggrTy,
   return Composite;
 }
 
+// If a function directly returns an aggregate-typed call result,
+// the ReturnInst carries an aggregate while the function signature
+// was rewritten to i32 by SPIRVPrepareFunctions. Rebuild the return value
+// via extractvalue/insertvalue so the regular spv_extractv/spv_insertv
+// lowering produces a valid OpReturnValue.
+void SPIRVEmitIntrinsics::reconstructAggregateReturns(Function &Func,
+                                                      IRBuilder<> &B) {
+  for (BasicBlock &BB : Func) {
+    auto *RI = dyn_cast<ReturnInst>(BB.getTerminator());
+    if (!RI)
+      continue;
+    Value *RetVal = RI->getReturnValue();
+    if (!RetVal || !RetVal->getType()->isAggregateType())
+      continue;
----------------
jmmartinez wrote:

Can we check the return type of `Func` outside of the loop and avoid completely this check?

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


More information about the llvm-commits mailing list