Skip to content

Commit e5b9e1d

Browse files
committed
[SPIR-V] Consistent handling of TargetExtTypes in emit-intrinsics
TargetExtType values are replaced with calls to `llvm.spv.track.constant`, with a `poison` value, but `llvm.spv.assign.type` was called with their original value. This PR updates the `assign.type` call to be consistent with the `track.constant` call. Fixes #134417.
1 parent a2c57e1 commit e5b9e1d

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,10 +1947,14 @@ void SPIRVEmitIntrinsics::insertAssignTypeIntrs(Instruction *I,
19471947
GR->buildAssignPtr(B, ElemTy ? ElemTy : deduceElementType(Op, true),
19481948
Op);
19491949
} else {
1950+
Value *OpTyVal = Op;
1951+
if (OpTy->isTargetExtTy()) {
1952+
OpTyVal = getNormalizedPoisonValue(OpTy);
1953+
}
19501954
CallInst *AssignCI =
19511955
buildIntrWithMD(Intrinsic::spv_assign_type, {OpTy},
1952-
getNormalizedPoisonValue(OpTy), Op, {}, B);
1953-
GR->addAssignPtrTypeInstr(Op, AssignCI);
1956+
getNormalizedPoisonValue(OpTy), OpTyVal, {}, B);
1957+
GR->addAssignPtrTypeInstr(OpTyVal, AssignCI);
19541958
}
19551959
}
19561960
}
@@ -2061,22 +2065,12 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
20612065
BPrepared = true;
20622066
}
20632067
Type *OpTy = Op->getType();
2064-
Value *OpTyVal = Op;
2065-
if (OpTy->isTargetExtTy())
2066-
OpTyVal = getNormalizedPoisonValue(OpTy);
20672068
Type *OpElemTy = GR->findDeducedElementType(Op);
20682069
Value *NewOp = Op;
20692070
if (OpTy->isTargetExtTy()) {
2071+
Value *OpTyVal = getNormalizedPoisonValue(OpTy);
20702072
NewOp = buildIntrWithMD(Intrinsic::spv_track_constant,
20712073
{OpTy, OpTyVal->getType()}, Op, OpTyVal, {}, B);
2072-
if (isPointerTy(OpTy)) {
2073-
if (OpElemTy) {
2074-
GR->buildAssignPtr(B, OpElemTy, NewOp);
2075-
} else {
2076-
insertTodoType(NewOp);
2077-
GR->buildAssignPtr(B, OpTy, NewOp);
2078-
}
2079-
}
20802074
}
20812075
if (!IsConstComposite && isPointerTy(OpTy) && OpElemTy != nullptr &&
20822076
OpElemTy != IntegerType::getInt8Ty(I->getContext())) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - | spirv-as - -o - | spirv-val %}
4+
5+
%literal_32 = type target("spirv.Literal", 32)
6+
%literal_true = type target("spirv.Literal", 1)
7+
8+
; CHECK-DAG: OpUnknown(21, 4) [[int_t:%[0-9]+]] 32 1
9+
%int_t = type target("spirv.Type", %literal_32, %literal_true, 21, 4, 32)
10+
11+
; CHECK-DAG: {{%[0-9]+}} = OpTypeFunction [[int_t]]
12+
define %int_t @foo() {
13+
entry:
14+
%v = alloca %int_t
15+
%i = load %int_t, ptr %v
16+
17+
; CHECK-DAG: [[i:%[0-9]+]] = OpUndef [[int_t]]
18+
; CHECK-DAG: OpReturnValue [[i]]
19+
ret %int_t %i
20+
}

0 commit comments

Comments
 (0)