[llvm] [SPIRV] Fix type mismatch assertion in insertvalue. (PR #143131)
Tim Besard via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 24 07:15:27 PDT 2025
https://github.com/maleadt updated https://github.com/llvm/llvm-project/pull/143131
>From 19aaa7cbc99e82065143e0d4476d73689f171bd4 Mon Sep 17 00:00:00 2001
From: Tim Besard <tim.besard at gmail.com>
Date: Fri, 6 Jun 2025 14:47:12 +0200
Subject: [PATCH 1/2] [SPIRV] Fix type mismatch assertion in insertvalue.
The code was incorrectly converting all undef arguments to i32, while
the `spv_insertv` intrinsics only expects that for the first operand,
representing the aggregate type.
---
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 11 ++++----
.../instructions/insertvalue-undef-ptr.ll | 27 +++++++++++++++++++
2 files changed, 33 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index cc95fde6a516d..8e467b5c700b0 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -1711,11 +1711,12 @@ Instruction *SPIRVEmitIntrinsics::visitInsertValueInst(InsertValueInst &I) {
B.SetInsertPoint(&I);
SmallVector<Type *, 1> Types = {I.getInsertedValueOperand()->getType()};
SmallVector<Value *> Args;
- for (auto &Op : I.operands())
- if (isa<UndefValue>(Op))
- Args.push_back(UndefValue::get(B.getInt32Ty()));
- else
- Args.push_back(Op);
+ Value *AggregateOp = I.getAggregateOperand();
+ if (isa<UndefValue>(AggregateOp))
+ Args.push_back(UndefValue::get(B.getInt32Ty()));
+ else
+ Args.push_back(AggregateOp);
+ Args.push_back(I.getInsertedValueOperand());
for (auto &Op : I.indices())
Args.push_back(B.getInt32(Op));
Instruction *NewI =
diff --git a/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll b/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
new file mode 100644
index 0000000000000..0676652ac1b39
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
@@ -0,0 +1,27 @@
+; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+
+; CHECK-LABEL: Begin function original_testcase
+define fastcc void @original_testcase() {
+top:
+ ; CHECK: OpCompositeInsert
+ %0 = insertvalue [1 x ptr] zeroinitializer, ptr poison, 0
+ ret void
+}
+
+; CHECK-LABEL: Begin function additional_testcases
+define fastcc void @additional_testcases() {
+top:
+ ; Test with different pointer types
+ ; CHECK: OpCompositeInsert
+ %1 = insertvalue [1 x ptr] zeroinitializer, ptr undef, 0
+ ; CHECK-NEXT: OpCompositeInsert
+ %2 = insertvalue {ptr, i32} zeroinitializer, ptr poison, 0
+ ; CHECK-NEXT: OpCompositeInsert
+ %3 = insertvalue {ptr, ptr} undef, ptr null, 0
+
+ ; Test with undef aggregate
+ ; CHECK-NEXT: OpCompositeInsert
+ %4 = insertvalue [1 x ptr] undef, ptr undef, 0
+
+ ret void
+}
>From b44d00d2e53b04fcc257772f7a36e6d5e3bcf450 Mon Sep 17 00:00:00 2001
From: Tim Besard <tim.besard at gmail.com>
Date: Thu, 24 Jul 2025 10:15:19 -0400
Subject: [PATCH 2/2] Update
llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
Co-authored-by: Michal Paszkowski <michal at michalpaszkowski.com>
---
llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll b/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
index 0676652ac1b39..b788f34bf7238 100644
--- a/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
+++ b/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
@@ -1,4 +1,5 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; CHECK-LABEL: Begin function original_testcase
define fastcc void @original_testcase() {
More information about the llvm-commits
mailing list