Skip to content

Commit ebfafa2

Browse files
[SPIR-V] Fix OpFunctionParameter vs. OpTypeFunction types for pointer arguments when there are functions with aggregate arguments (#115044)
The goal of the PR is to ensure that if module contains functions with mutated signature (due to preprocessing of aggregate types), functions still are going through re-creating of function type to preserve pointee type information for arguments. This fixes a bug when a module with (1) a function having aggregate arguments and/or return, and (2) at least two functions with signatures different only wrt. pointee types is translated so that one of two similar functions gets an incorrect OpFunctionParameter type that is different from the corresponding OpTypeFunction definition. A reproducer is attached as a new test case.
1 parent 3d4d033 commit ebfafa2

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ static FunctionType *
101101
fixFunctionTypeIfPtrArgs(SPIRVGlobalRegistry *GR, const Function &F,
102102
FunctionType *FTy, const SPIRVType *SRetTy,
103103
const SmallVector<SPIRVType *, 4> &SArgTys) {
104-
if (F.getParent()->getNamedMetadata("spv.cloned_funcs"))
105-
return FTy;
106-
107104
bool hasArgPtrs = false;
108105
for (auto &Arg : F.args()) {
109106
// check if it's an instance of a non-typed PointerType
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; The goal of the test case is to ensure that if module contains functions with mutated signature
2+
; (due to preprocessing of aggregate types), functions still are going through re-creating of
3+
; function type to preserve pointee type information for arguments.
4+
5+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
6+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
7+
8+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
9+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
10+
11+
; CHECK-DAG: %[[#Int8:]] = OpTypeInt 8 0
12+
; CHECK-DAG: %[[#Half:]] = OpTypeFloat 16
13+
; CHECK-DAG: %[[#Struct:]] = OpTypeStruct %[[#Half]]
14+
; CHECK-DAG: %[[#Void:]] = OpTypeVoid
15+
; CHECK-DAG: %[[#PtrInt8:]] = OpTypePointer CrossWorkgroup %[[#Int8:]]
16+
; CHECK-DAG: %[[#FooType:]] = OpTypeFunction %[[#Void]] %[[#PtrInt8]] %[[#Struct]]
17+
; CHECK-DAG: %[[#Int64:]] = OpTypeInt 64 0
18+
; CHECK-DAG: %[[#PtrInt64:]] = OpTypePointer CrossWorkgroup %[[#Int64]]
19+
; CHECK-DAG: %[[#BarType:]] = OpTypeFunction %[[#Void]] %[[#PtrInt64]] %[[#Struct]]
20+
; CHECK: OpFunction %[[#Void]] None %[[#FooType]]
21+
; CHECK: OpFunctionParameter %[[#PtrInt8]]
22+
; CHECK: OpFunctionParameter %[[#Struct]]
23+
; CHECK: OpFunction %[[#Void]] None %[[#BarType]]
24+
; CHECK: OpFunctionParameter %[[#PtrInt64]]
25+
; CHECK: OpFunctionParameter %[[#Struct]]
26+
27+
%t_half = type { half }
28+
29+
define spir_kernel void @foo(ptr addrspace(1) %a, %t_half %b) {
30+
entry:
31+
ret void
32+
}
33+
34+
35+
define spir_kernel void @bar(ptr addrspace(1) %a, %t_half %b) {
36+
entry:
37+
%r = getelementptr inbounds i64, ptr addrspace(1) %a, i64 0
38+
ret void
39+
}
40+
41+
declare spir_func %t_half @_Z29__spirv_SpecConstantComposite(half)

0 commit comments

Comments
 (0)