Skip to content

Commit e60b633

Browse files
[SPIR-V] Consistent handling of TargetExtTypes in emit-intrinsics (#135682)
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. --------- Co-authored-by: Steven Perron <[email protected]>
1 parent 8083944 commit e60b633

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,10 +1961,16 @@ void SPIRVEmitIntrinsics::insertAssignTypeIntrs(Instruction *I,
19611961
GR->buildAssignPtr(B, ElemTy ? ElemTy : deduceElementType(Op, true),
19621962
Op);
19631963
} else {
1964+
Value *OpTyVal = Op;
1965+
if (OpTy->isTargetExtTy()) {
1966+
// We need to do this in order to be consistent with how target ext
1967+
// types are handled in `processInstrAfterVisit`
1968+
OpTyVal = getNormalizedPoisonValue(OpTy);
1969+
}
19641970
CallInst *AssignCI =
19651971
buildIntrWithMD(Intrinsic::spv_assign_type, {OpTy},
1966-
getNormalizedPoisonValue(OpTy), Op, {}, B);
1967-
GR->addAssignPtrTypeInstr(Op, AssignCI);
1972+
getNormalizedPoisonValue(OpTy), OpTyVal, {}, B);
1973+
GR->addAssignPtrTypeInstr(OpTyVal, AssignCI);
19681974
}
19691975
}
19701976
}
@@ -2075,22 +2081,14 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
20752081
BPrepared = true;
20762082
}
20772083
Type *OpTy = Op->getType();
2078-
Value *OpTyVal = Op;
2079-
if (OpTy->isTargetExtTy())
2080-
OpTyVal = getNormalizedPoisonValue(OpTy);
20812084
Type *OpElemTy = GR->findDeducedElementType(Op);
20822085
Value *NewOp = Op;
20832086
if (OpTy->isTargetExtTy()) {
2087+
// Since this value is replaced by poison, we need to do the same in
2088+
// `insertAssignTypeIntrs`.
2089+
Value *OpTyVal = getNormalizedPoisonValue(OpTy);
20842090
NewOp = buildIntrWithMD(Intrinsic::spv_track_constant,
20852091
{OpTy, OpTyVal->getType()}, Op, OpTyVal, {}, B);
2086-
if (isPointerTy(OpTy)) {
2087-
if (OpElemTy) {
2088-
GR->buildAssignPtr(B, OpElemTy, NewOp);
2089-
} else {
2090-
insertTodoType(NewOp);
2091-
GR->buildAssignPtr(B, OpTy, NewOp);
2092-
}
2093-
}
20942092
}
20952093
if (!IsConstComposite && isPointerTy(OpTy) && OpElemTy != nullptr &&
20962094
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)