Skip to content

[SPIRV] Fix type mismatch assertion in insertvalue. #143131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/SPIRV/instructions/insertvalue-undef-ptr.ll
Original file line number Diff line number Diff line change
@@ -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
}
Loading