Skip to content

Commit 5923a27

Browse files
improve type inference
1 parent 3f7005f commit 5923a27

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ CallInst *SPIRVEmitIntrinsics::buildSpvPtrcast(Function *F, Value *Op,
450450
}
451451

452452
void SPIRVEmitIntrinsics::propagateElemType(Value *Op, Type *ElemTy) {
453-
// CallInst *PtrCasted = buildSpvPtrcast(Op, ElemTy);
454453
SmallVector<User *> Users(Op->users());
455454
for (auto *U : Users) {
456455
if (!isa<Instruction>(U))
@@ -1095,8 +1094,9 @@ void SPIRVEmitIntrinsics::deduceOperandElementType(
10951094
{B.getInt32(getPointerAddressSpace(OpTy))}, B);
10961095
GR->addAssignPtrTypeInstr(Op, CI);
10971096
} else {
1097+
Type *PrevElemTy = GR->findDeducedElementType(Op);
10981098
updateAssignType(AssignCI, Op, OpTyVal);
1099-
propagateElemTypeRec(Op, KnownElemTy, GR->findDeducedElementType(Op));
1099+
propagateElemTypeRec(Op, KnownElemTy, PrevElemTy);
11001100
}
11011101
} else {
11021102
eraseTodoType(Op);
@@ -1412,10 +1412,13 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
14121412
if (mayUpdateOpType(Pointer)) {
14131413
// If this wouldn't be the first spv_ptrcast but existing type info is
14141414
// uncomplete, update spv_assign_ptr_type arguments.
1415-
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr(Pointer))
1415+
if (CallInst *AssignCI = GR->findAssignPtrTypeInstr(Pointer)) {
1416+
Type *PrevElemTy = GR->findDeducedElementType(Pointer);
14161417
updateAssignType(AssignCI, Pointer, ExpectedElementVal);
1417-
else
1418+
propagateElemTypeRec(Pointer, ExpectedElementType, PrevElemTy);
1419+
} else {
14181420
buildAssignPtr(B, ExpectedElementType, Pointer);
1421+
}
14191422
return;
14201423
}
14211424
}
@@ -1428,6 +1431,7 @@ void SPIRVEmitIntrinsics::replacePointerOperandWithPtrCast(
14281431
I->setOperand(OperandToReplace, PtrCastI);
14291432
// We need to set up a pointee type for the newly created spv_ptrcast.
14301433
buildAssignPtr(B, ExpectedElementType, PtrCastI);
1434+
//propagateElemType(Pointer, ExpectedElementType);
14311435
}
14321436

14331437
void SPIRVEmitIntrinsics::insertPtrCastOrAssignTypeInstr(Instruction *I,

llvm/test/CodeGen/SPIRV/pointers/phi-valid-operand-types.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
; CHECK-DAG: %[[#PtrInt:]] = OpTypePointer Function %[[#Int]]
88
; CHECK: %[[#R1:]] = OpFunctionCall %[[#PtrChar]] %[[#]]
99
; CHECK: %[[#R2:]] = OpFunctionCall %[[#PtrInt]] %[[#]]
10-
; CHECK-2: %[[#]] = OpBitcast %[[#PtrChar]] %[[#R2]]
11-
; CHECK-2: OpPhi %[[#PtrChar]] %[[#R1]] %[[#]] %[[#]] %[[#]]
10+
; CHECK: %[[#Casted:]] = OpBitcast %[[#PtrChar]] %[[#R2]]
11+
; CHECK: OpPhi %[[#PtrChar]] %[[#R1]] %[[#]] %[[#Casted]] %[[#]]
1212

1313
define ptr @foo(i1 %arg) {
1414
entry:

0 commit comments

Comments
 (0)