[llvm] [SPIR-V] Fix aggregate PHI type mismatch in loops (PR #186086)

Juan Manuel Martinez CaamaƱo via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 20 03:05:52 PDT 2026


================
@@ -1490,6 +1491,30 @@ void SPIRVEmitIntrinsics::replaceMemInstrUses(Instruction *Old,
     } else if (isMemInstrToReplace(U) || isa<ReturnInst>(U) ||
                isa<CallInst>(U)) {
       U->replaceUsesOfWith(Old, New);
+    } else if (auto *Phi = dyn_cast<PHINode>(U)) {
+      if (Phi->getType() != New->getType()) {
+        Phi->mutateType(New->getType());
+        Phi->replaceUsesOfWith(Old, New);
+        // Convert extractvalue users of the mutated PHI to spv_extractv
+        SmallVector<ExtractValueInst *, 4> EVUsers;
+        for (User *PhiUser : Phi->users())
+          if (auto *EV = dyn_cast<ExtractValueInst>(PhiUser))
+            EVUsers.push_back(EV);
+        for (ExtractValueInst *EV : EVUsers) {
+          B.SetInsertPoint(EV);
+          SmallVector<Value *> Args;
+          Args.push_back(Phi);
+          for (unsigned Idx : EV->indices())
+            Args.push_back(B.getInt32(Idx));
----------------
jmmartinez wrote:

```suggestion
          SmallVector<Value *> Args(EV->operand_values());
```
The first operand of the `ExtractValueInst` is the aggregate (the `Phi`) and the rest are the indices.

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


More information about the llvm-commits mailing list