Skip to content

Commit 58805dd

Browse files
[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 #127977 --------- Co-authored-by: Michal Paszkowski <michal@michalpaszkowski.com>
1 parent 2284ce0 commit 58805dd

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,11 +1909,12 @@ Instruction *SPIRVEmitIntrinsics::visitInsertValueInst(InsertValueInst &I) {
19091909
B.SetInsertPoint(&I);
19101910
SmallVector<Type *, 1> Types = {I.getInsertedValueOperand()->getType()};
19111911
SmallVector<Value *> Args;
1912-
for (auto &Op : I.operands())
1913-
if (isa<UndefValue>(Op))
1914-
Args.push_back(UndefValue::get(B.getInt32Ty()));
1915-
else
1916-
Args.push_back(Op);
1912+
Value *AggregateOp = I.getAggregateOperand();
1913+
if (isa<UndefValue>(AggregateOp))
1914+
Args.push_back(UndefValue::get(B.getInt32Ty()));
1915+
else
1916+
Args.push_back(AggregateOp);
1917+
Args.push_back(I.getInsertedValueOperand());
19171918
for (auto &Op : I.indices())
19181919
Args.push_back(B.getInt32(Op));
19191920
Instruction *NewI =
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-LABEL: Begin function original_testcase
5+
define fastcc void @original_testcase() {
6+
top:
7+
; CHECK: OpCompositeInsert
8+
%0 = insertvalue [1 x ptr] zeroinitializer, ptr poison, 0
9+
ret void
10+
}
11+
12+
; CHECK-LABEL: Begin function additional_testcases
13+
define fastcc void @additional_testcases() {
14+
top:
15+
; Test with different pointer types
16+
; CHECK: OpCompositeInsert
17+
%1 = insertvalue [1 x ptr] zeroinitializer, ptr undef, 0
18+
; CHECK-NEXT: OpCompositeInsert
19+
%2 = insertvalue {ptr, i32} zeroinitializer, ptr poison, 0
20+
; CHECK-NEXT: OpCompositeInsert
21+
%3 = insertvalue {ptr, ptr} undef, ptr null, 0
22+
23+
; Test with undef aggregate
24+
; CHECK-NEXT: OpCompositeInsert
25+
%4 = insertvalue [1 x ptr] undef, ptr undef, 0
26+
27+
ret void
28+
}

0 commit comments

Comments
 (0)