Skip to content

Commit e62b5aa

Browse files
authored
[SYCL] Force inline spec constant retrieval function to help BEs at -O0. (#6035)
kernel_handler::get_specialization_constant translates to a sequence of calls with __spirv_SpecConstant in the end under -O0, which hurts BE ability to guess actual constant value at the call site, especially since it is also invoked with -O0. Forcing inlining of all the participating functions turns the callsite into single __spirv_SpecConstant, which is then replaced by actual constant. Signed-off-by: Konstantin S Bobrovsky <konstantin.s.bobrovsky@intel.com>
1 parent ec57cd7 commit e62b5aa

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

sycl/include/CL/sycl/kernel_handler.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class kernel_handler {
2323
public:
2424
#if __cplusplus >= 201703L
2525
template <auto &S>
26-
typename std::remove_reference_t<decltype(S)>::value_type
26+
__SYCL_ALWAYS_INLINE typename std::remove_reference_t<decltype(S)>::value_type
2727
get_specialization_constant() {
2828
#ifdef __SYCL_DEVICE_ONLY__
2929
return getSpecializationConstantOnDevice<S>();
@@ -49,7 +49,7 @@ class kernel_handler {
4949
auto &S,
5050
typename T = typename std::remove_reference_t<decltype(S)>::value_type,
5151
std::enable_if_t<std::is_fundamental_v<T>> * = nullptr>
52-
T getSpecializationConstantOnDevice() {
52+
__SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
5353
const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
5454
return __sycl_getScalar2020SpecConstantValue<T>(
5555
SymbolicID, &S, MSpecializationConstantsBuffer);
@@ -58,7 +58,7 @@ class kernel_handler {
5858
auto &S,
5959
typename T = typename std::remove_reference_t<decltype(S)>::value_type,
6060
std::enable_if_t<std::is_compound_v<T>> * = nullptr>
61-
T getSpecializationConstantOnDevice() {
61+
__SYCL_ALWAYS_INLINE T getSpecializationConstantOnDevice() {
6262
const char *SymbolicID = __builtin_sycl_unique_stable_id(S);
6363
return __sycl_getComposite2020SpecConstantValue<T>(
6464
SymbolicID, &S, MSpecializationConstantsBuffer);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clangxx -O0 -fsycl -fsycl-device-only -Xclang -emit-llvm %s -o - | FileCheck %s
2+
// This test checks that even under -O0 the entire call chain starting from
3+
// kh.get_specialization_constant and ending with
4+
// __sycl_getScalar2020SpecConstantValue gets inlined.
5+
#include <CL/sycl.hpp>
6+
7+
using namespace cl::sycl;
8+
9+
constexpr specialization_id<unsigned int> SPEC_CONST(1024);
10+
11+
SYCL_EXTERNAL unsigned int foo(kernel_handler &kh) {
12+
return kh.get_specialization_constant<SPEC_CONST>();
13+
}
14+
15+
// CHECK-LABEL: define dso_local spir_func noundef i32 @_Z3foo{{.*}} {
16+
// CHECK-NOT: {{.*}}spir_func
17+
// CHECK: %{{.*}} = {{.*}}call spir_func {{.*}}i32 @_Z37__sycl_getScalar2020SpecConstantValue
18+
// CHECK-NOT: {{.*}}spir_func
19+
// CHECK-LABEL: }

0 commit comments

Comments
 (0)