Skip to content

Commit cf0cf23

Browse files
committed
[SYCL] Adjust GCC workaround and its scope
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 ceed6af commit cf0cf23

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

sycl/source/builtins/relational_functions.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,34 @@ 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 GCC_VERSION \
76+
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
77+
78+
#if defined(__GNUC__) && !defined(__clang__) && \
79+
((GCC_VERSION >= 100000 && GCC_VERSION < 110000) || \
80+
(GCC_VERSION >= 110000 && GCC_VERSION < 110500) || \
81+
(GCC_VERSION >= 120000 && GCC_VERSION < 120400) || \
82+
(GCC_VERSION >= 130000 && GCC_VERSION < 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_VERSION
85102

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

0 commit comments

Comments
 (0)