Skip to content

Commit f894d08

Browse files
authored
[SYCL] Adjust GCC workaround and its scope (#13144)
Previously we were hard-coding an -O2 optimization level for the 'signbit' builtin for all versions of GCC. Despite this workaround, I found locally that I was unable to build with GCC versions 12.2, 12.3, and 13.2. Reducing the optimization level to -O1 allowed me to progress. This seems to follow the bug report already linked, which had test cases at -O2 which were also failing. With this in mind, we can also restrict the GCC versions we apply the workaround to, so that more modern compilers should "just work" without us having to do anything. That should save someone having to investigate a performance report a year or so down the line...
1 parent f64a32a commit f894d08

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

sycl/source/builtins/relational_functions.cpp

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,36 @@ REL_BUILTIN(ONE_ARG, isnormal)
7171
REL_BUILTIN(TWO_ARGS, isunordered)
7272
REL_BUILTIN_CUSTOM(TWO_ARGS, isordered,
7373
([](auto x, auto y) { return !sycl::isunordered(x, y); }))
74-
#if defined(__GNUC__) && !defined(__clang__)
74+
75+
#define _SYCL_BUILTINS_GCC_VER \
76+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
77+
78+
#if defined(__GNUC__) && !defined(__clang__) && \
79+
((_SYCL_BUILTINS_GCC_VER >= 100000 && _SYCL_BUILTINS_GCC_VER < 110000) || \
80+
(_SYCL_BUILTINS_GCC_VER >= 110000 && _SYCL_BUILTINS_GCC_VER < 110500) || \
81+
(_SYCL_BUILTINS_GCC_VER >= 120000 && _SYCL_BUILTINS_GCC_VER < 120400) || \
82+
(_SYCL_BUILTINS_GCC_VER >= 130000 && _SYCL_BUILTINS_GCC_VER < 130300))
7583
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112816
76-
#pragma GCC push_options
77-
#pragma GCC optimize("-O2")
84+
// The reproducers in that ticket only affect GCCs 10 to 13. Release
85+
// branches 11.5, 12.4, and 13.3 have been updated with the fix; release branch
86+
// 10 hasn't, so all GCCs 10.x are considered affected.
87+
#define GCC_PR112816_DISABLE_OPT \
88+
_Pragma("GCC push_options") _Pragma("GCC optimize(\"-O1\")")
89+
#define GCC_PR112816_RESTORE_OPT _Pragma("GCC pop_options")
90+
#else
91+
#define GCC_PR112816_DISABLE_OPT
92+
#define GCC_PR112816_RESTORE_OPT
7893
#endif
7994

95+
GCC_PR112816_DISABLE_OPT
96+
8097
REL_BUILTIN(ONE_ARG, signbit)
8198

82-
#if defined(__GNUC__) && !defined(__clang__)
83-
#pragma GCC pop_options
84-
#endif
99+
GCC_PR112816_RESTORE_OPT
100+
101+
#undef GCC_PR112816_RESTORE_OPT
102+
#undef GCC_PR112816_DISABLE_OPT
103+
#undef _SYCL_BUILTINS_GCC_VER
85104

86105
HOST_IMPL(bitselect, [](auto x, auto y, auto z) {
87106
using T0 = decltype(x);

0 commit comments

Comments
 (0)