Skip to content

Commit f3d9419

Browse files
obrotowyigcbot
authored andcommitted
Make LowerGPCallArg skip arguments with ByVal attribute
Lowering byval arguments had been causing bug, when origin addrspace was different than private.
1 parent 34b8ee8 commit f3d9419

File tree

7 files changed

+134
-3
lines changed

7 files changed

+134
-3
lines changed

IGC/Compiler/Optimizer/OpenCLPasses/ErrorCheckPass/ErrorCheckPass.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,26 @@ bool ErrorCheck::runOnFunction(Function &F) {
4242
if (isEntryFunc(getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils(), &F)) {
4343
checkArgsSize(F);
4444
}
45-
45+
checkByValAddrSpace(F);
4646
return m_hasError;
4747
}
4848

49+
void ErrorCheck::checkByValAddrSpace(Function &F) {
50+
auto Ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
51+
for (auto &arg : F.args()) {
52+
Type *argTy = arg.getType();
53+
if (arg.hasByValAttr()) {
54+
if (argTy->getPointerAddressSpace() != ADDRESS_SPACE_GENERIC &&
55+
argTy->getPointerAddressSpace() != ADDRESS_SPACE_PRIVATE) {
56+
std::string ErrorMsg = "ByVal argument with addrspace different than Generic/Private is not supported.";
57+
Ctx->EmitError(ErrorMsg.c_str(), &F);
58+
59+
m_hasError = true;
60+
}
61+
}
62+
}
63+
}
64+
4965
void ErrorCheck::checkArgsSize(Function &F) {
5066
auto Ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
5167
auto MdUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();

IGC/Compiler/Optimizer/OpenCLPasses/ErrorCheckPass/ErrorCheckPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ErrorCheck : public llvm::FunctionPass, public llvm::InstVisitor<ErrorChec
4040
bool m_hasError = false;
4141

4242
void checkArgsSize(llvm::Function &F);
43-
43+
void checkByValAddrSpace(llvm::Function &F);
4444
void handleFP64EmulationMode(llvm::Instruction &I);
4545
};
4646

IGC/Compiler/Optimizer/OpenCLPasses/GenericAddressResolution/LowerGPCallArg.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ bool LowerGPCallArg::runOnModule(llvm::Module &M) {
7373

7474
Type *argTy = arg.getType();
7575
if (argTy->isPointerTy() && argTy->getPointerAddressSpace() == ADDRESS_SPACE_GENERIC) {
76-
if (auto originAddrSpace = getOriginAddressSpace(F, arg.getArgNo()))
76+
auto originAddrSpace = getOriginAddressSpace(F, arg.getArgNo());
77+
// We don't optimize ByVal arguments if its origin != private because it's been causing issues
78+
// We're currently investigating if we should support byval arguments for addrspaces other than private/generic
79+
if (originAddrSpace && !(arg.hasByValAttr() && originAddrSpace != ADDRESS_SPACE_PRIVATE))
7780
genericArgsInfo.push_back({arg.getArgNo(), originAddrSpace.value()});
7881
}
7982
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --igc-error-check -S < %s 2>&1 | FileCheck %s
10+
; ------------------------------------------------
11+
; ErrorCheck
12+
; ------------------------------------------------
13+
14+
; CHECK: error: ByVal argument with addrspace different than Generic/Private is not supported.
15+
16+
define void @test(i32 addrspace(3)* byval (i32) %p1) {
17+
ret void
18+
}
19+
20+
!0 = !{void (i32 addrspace(3)*)* @test, !1}
21+
!1 = !{!2, !3}
22+
!2 = !{!"function_type", i32 0}
23+
!3 = !{!"implicit_arg_desc"}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --opaque-pointers --igc-error-check -S < %s 2>&1 | FileCheck %s
10+
; ------------------------------------------------
11+
; ErrorCheck
12+
; ------------------------------------------------
13+
14+
; CHECK: error: ByVal argument with addrspace different than Generic/Private is not supported.
15+
16+
define void @test(i32 addrspace(3)* byval (i32) %p1) {
17+
ret void
18+
}
19+
20+
!0 = !{void (i32 addrspace(3)*)* @test, !1}
21+
!1 = !{!2, !3}
22+
!2 = !{!"function_type", i32 0}
23+
!3 = !{!"implicit_arg_desc"}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --typed-pointers --igc-lower-gp-arg -S < %s 2>&1 | FileCheck %s
10+
11+
@a = internal addrspace(3) global i32 0
12+
; CHECK: [[A:@.*]] = internal addrspace(3) global i32 0
13+
14+
define i32 @func(i32 addrspace(4)* byval (i32) %p1) {
15+
; CHECK: define i32 [[FUNC:@.*]](i32 addrspace(4)* byval(i32) [[P1:%.*]]) {
16+
%1 = load i32, i32 addrspace(4)* %p1
17+
ret i32 %1
18+
}
19+
20+
define void @kernel() {
21+
; CHECK: [[TMP1:%.*]] = addrspacecast i32 addrspace(3)* [[A]] to i32 addrspace(4)*
22+
%1 = addrspacecast i32 addrspace(3)* @a to i32 addrspace(4)*
23+
call i32 @func(i32 addrspace(4)* byval(i32) %1)
24+
ret void
25+
}
26+
27+
!igc.functions = !{!0, !3}
28+
29+
!0 = !{void ()* @kernel, !1}
30+
!3 = !{i32 (i32 addrspace(4)*)* @func, !1}
31+
32+
!1 = !{!2}
33+
!2 = !{!"function_type", i32 0}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt --opaque-pointers --igc-lower-gp-arg -S < %s 2>&1 | FileCheck %s
10+
11+
@a = internal addrspace(3) global i32 0
12+
; CHECK: [[A:@.*]] = internal addrspace(3) global i32 0
13+
14+
define i32 @func(i32 addrspace(4)* byval (i32) %p1) {
15+
; CHECK: define i32 [[FUNC:@.*]](ptr addrspace(4) byval(i32) [[P1:%.*]]) {
16+
%1 = load i32, i32 addrspace(4)* %p1
17+
ret i32 %1
18+
}
19+
20+
define void @kernel() {
21+
; CHECK: [[TMP1:%.*]] = addrspacecast ptr addrspace(3) [[A]] to ptr addrspace(4)
22+
%1 = addrspacecast i32 addrspace(3)* @a to i32 addrspace(4)*
23+
call i32 @func(i32 addrspace(4)* byval(i32) %1)
24+
ret void
25+
}
26+
27+
!igc.functions = !{!0, !3}
28+
29+
!0 = !{void ()* @kernel, !1}
30+
!3 = !{i32 (i32 addrspace(4)*)* @func, !1}
31+
32+
!1 = !{!2}
33+
!2 = !{!"function_type", i32 0}

0 commit comments

Comments
 (0)