Skip to content

Commit 3aa9980

Browse files
Prevent type change of GEP results in type inference
1 parent e3f5269 commit 3aa9980

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,7 @@ bool SPIRVEmitIntrinsics::processFunctionPointers(Module &M) {
23072307

23082308
// Apply types parsed from demangled function declarations.
23092309
void SPIRVEmitIntrinsics::applyDemangledPtrArgTypes(IRBuilder<> &B) {
2310+
DenseMap<Function *, CallInst *> Ptrcasts;
23102311
for (auto It : FDeclPtrTys) {
23112312
Function *F = It.first;
23122313
for (auto *U : F->users()) {
@@ -2326,6 +2327,9 @@ void SPIRVEmitIntrinsics::applyDemangledPtrArgTypes(IRBuilder<> &B) {
23262327
B.SetCurrentDebugLocation(DebugLoc());
23272328
buildAssignPtr(B, ElemTy, Arg);
23282329
}
2330+
} else if (isa<GetElementPtrInst>(Param)) {
2331+
replaceUsesOfWithSpvPtrcast(Param, normalizeType(ElemTy), CI,
2332+
Ptrcasts);
23292333
} else if (isa<Instruction>(Param)) {
23302334
GR->addDeducedElementType(Param, normalizeType(ElemTy));
23312335
// insertAssignTypeIntrs() will complete buildAssignPtr()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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-DAG: %[[#Char:]] = OpTypeInt 8 0
5+
; CHECK-DAG: %[[#Long:]] = OpTypeInt 32 0
6+
; CHECK-DAG: %[[#CharPtr:]] = OpTypePointer CrossWorkgroup %[[#Char]]
7+
; CHECK-DAG: %[[#LongPtr:]] = OpTypePointer CrossWorkgroup %[[#Long]]
8+
; CHECK-DAG: %[[#LongPtrWG:]] = OpTypePointer Workgroup %[[#Long]]
9+
; CHECK: OpFunction
10+
; CHECK: OpFunctionParameter
11+
; CHECK: %[[#Dest:]] = OpFunctionParameter %[[#CharPtr]]
12+
; CHECK: %[[#Src:]] = OpFunctionParameter %[[#LongPtrWG]]
13+
; CHECK: %[[#InDest:]] = OpInBoundsPtrAccessChain %[[#CharPtr]] %[[#Dest]] %[[#]]
14+
; CHECK: %[[#InDestCasted:]] = OpBitcast %[[#LongPtr]] %[[#InDest]]
15+
; CHECK: OpGroupAsyncCopy %[[#]] %[[#]] %[[#InDestCasted]] %[[#Src]] %[[#]] %[[#]] %[[#]]
16+
17+
define spir_kernel void @foo(i64 %idx, ptr addrspace(1) %dest, ptr addrspace(3) %src) {
18+
%p1 = getelementptr inbounds i8, ptr addrspace(1) %dest, i64 %idx
19+
%res = tail call spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyjPU3AS1iPU3AS3Kimm9ocl_event(i32 2, ptr addrspace(1) %p1, ptr addrspace(3) %src, i64 128, i64 1, target("spirv.Event") zeroinitializer)
20+
ret void
21+
}
22+
23+
; For this test case the mangling is important.
24+
declare dso_local spir_func target("spirv.Event") @_Z22__spirv_GroupAsyncCopyjPU3AS1iPU3AS3Kimm9ocl_event(i32, ptr addrspace(1), ptr addrspace(3), i64, i64, target("spirv.Event"))

0 commit comments

Comments
 (0)