[llvm] 58805dd - [SPIRV] Fix type mismatch assertion in insertvalue. (#143131)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 28 04:13:44 PDT 2025
Author: Tim Besard
Date: 2025-09-28T04:13:41-07:00
New Revision: 58805dd9ede08df777e3e4486493b3a70c5124c7
URL: https://github.com/llvm/llvm-project/commit/58805dd9ede08df777e3e4486493b3a70c5124c7
DIFF: https://github.com/llvm/llvm-project/commit/58805dd9ede08df777e3e4486493b3a70c5124c7.diff
LOG: [SPIRV] Fix type mismatch assertion in insertvalue. (#143131)
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.
Fixes https://github.com/llvm/llvm-project/issues/127977
---------
Co-authored-by: Michal Paszkowski <michal at michalpaszkowski.com>
Added:
llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
Modified:
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index f5a49e2b47363..704edd3139260 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -1909,11 +1909,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..b788f34bf7238
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
@@ -0,0 +1,28 @@
+; 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() {
+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
diff erent 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
+}
More information about the llvm-commits
mailing list