Skip to content

Commit d195b1e

Browse files
ficoligcbot
authored andcommitted
Prevent SIMD size change with StackOverflowDetection
Do not count stackoverflow detection methods when checking if kernel has subroutine.
1 parent 55afc37 commit d195b1e

File tree

5 files changed

+46
-6
lines changed

5 files changed

+46
-6
lines changed

IGC/Compiler/CISACodeGen/GenCodeGenModule.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ namespace IGC {
143143
bool isSingle() const {
144144
return (Functions.size() == 1 && Functions.front()->size() == 1);
145145
}
146+
/// \brief Only one function in this group ignoring stack overflow detection methods
147+
bool isSingleIgnoringStackOverflowDetection() const {
148+
auto isNotStackOverflowDetection = [](const llvm::Function* F) {
149+
return !F->getName().startswith("__stackoverflow_detection") && !F->getName().startswith("__stackoverflow_init");
150+
};
151+
return (Functions.size() == 1 &&
152+
std::count_if(Functions.front()->begin(), Functions.front()->end(), isNotStackOverflowDetection) == 1);
153+
}
146154
/// \brief Function group has a subroutine
147155
bool hasSubroutine() const {
148156
return m_hasSubroutine;

IGC/Compiler/CISACodeGen/OpenCLKernelCodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3700,7 +3700,7 @@ namespace IGC
37003700
auto FG = m_FGA ? m_FGA->getGroup(&F) : nullptr;
37013701
bool hasStackCall = FG && FG->hasStackCall();
37023702
bool isIndirectGroup = FG && m_FGA->isIndirectCallGroup(FG);
3703-
bool hasSubroutine = FG && !FG->isSingle() && !hasStackCall && !isIndirectGroup;
3703+
bool hasSubroutine = FG && !FG->isSingleIgnoringStackOverflowDetection() && !hasStackCall && !isIndirectGroup;
37043704
bool forceLowestSIMDForStackCalls = IGC_IS_FLAG_ENABLED(ForceLowestSIMDForStackCalls) && (hasStackCall || isIndirectGroup);
37053705

37063706

IGC/ocloc_tests/features/stack_overflow_detection/stack_overflow_detection_no_vla.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
; RUN: ocloc compile -spirv_input -file %t.spv -options " -igc_opts 'DumpVISAASMToConsole=1,StackOverflowDetection=1'" -device pvc | FileCheck %s --check-prefix=CHECK-VISA
3030

3131
; CHECK-VISA: .kernel "test_simple"
32-
; CHECK-VISA-NOT: call (M1, {{(8)|(16)}}) __stackoverflow_init{{.*}}
33-
; CHECK-VISA-NOT: call (M1, {{(8)|(16)}}) __stackoverflow_detection{{.*}}
32+
; CHECK-VISA-NOT: call (M1, {{(8)|(16)|(32)}}) __stackoverflow_init{{.*}}
33+
; CHECK-VISA-NOT: call (M1, {{(8)|(16)|(32)}}) __stackoverflow_detection{{.*}}
3434

3535

3636
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"

IGC/ocloc_tests/features/stack_overflow_detection/stack_overflow_detection_vla.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
; RUN: ocloc compile -spirv_input -file %t.spv -options " -igc_opts 'DumpVISAASMToConsole=1,StackOverflowDetection=1'" -device pvc | FileCheck %s --check-prefix=CHECK-VISA
2020

2121
; CHECK-VISA: .kernel "test_simple"
22-
; CHECK-VISA: call (M1, {{(8)|(16)}}) __stackoverflow_init{{.*}}
23-
; CHECK-VISA-NOT: call (M1, {{(8)|(16)}}) __stackoverflow_init{{.*}}
24-
; CHECK-VISA: call (M1, {{(8)|(16)}}) __stackoverflow_detection{{.*}}
22+
; CHECK-VISA: call (M1, {{(8)|(16)|(32)}}) __stackoverflow_init{{.*}}
23+
; CHECK-VISA-NOT: call (M1, {{(8)|(16)|(32)}}) __stackoverflow_init{{.*}}
24+
; CHECK-VISA: call (M1, {{(8)|(16)|(32)}}) __stackoverflow_detection{{.*}}
2525
;
2626
; CHECK-VISA: warning: VLA has been detected
2727

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
// This test checks if calls to stack overflow detection subroutines don't change kernel SIMD size.
9+
10+
// REQUIRES: regkeys, pvc-supported
11+
12+
// RUN: ocloc compile -file %s -options " -igc_opts 'DumpVISAASMToConsole=1,StackOverflowDetection=1'" -device pvc | FileCheck %s --check-prefix=CHECK-VISA
13+
14+
// CHECK-VISA: .kernel "test_nosubroutines"
15+
// CHECK-VISA-NOT: .function
16+
// CHECK-VISA: .kernel_attr SimdSize=32
17+
18+
// CHECK-VISA: .kernel "test_subroutines"
19+
// CHECK-VISA-NOT: .function
20+
// CHECK-VISA: .kernel_attr SimdSize=16
21+
22+
int fact(int n) {
23+
return n < 2 ? 1 : n*fact(n-1);
24+
}
25+
26+
kernel void test_subroutines(global int* out, int n) {
27+
out[0] = fact(n);
28+
}
29+
30+
kernel void test_nosubroutines(global int* out, int n) {
31+
out[0] = n;
32+
}

0 commit comments

Comments
 (0)