1/*******************************************************************************
2* Copyright 2020-2021 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef COMPILER_WORKAROUNDS_HPP
18#define COMPILER_WORKAROUNDS_HPP
19
20// Workaround 01: clang.
21//
22// Clang has an issue [1] with `#pragma omp simd` that might lead to segfault.
23// The essential conditions are:
24// 1. Optimization level is O1 or O2. Surprisingly, O3 is fine.
25// 2. Conditional check inside the vectorization loop.
26// Since there is no reliable way to determine the first condition, we disable
27// vectorization for clang altogether for now.
28//
29// [1] https://bugs.llvm.org/show_bug.cgi?id=48104
30#if (defined __clang_major__) && (__clang_major__ >= 6)
31#define CLANG_WA_01_SAFE_TO_USE_OMP_SIMD 0
32#else
33#define CLANG_WA_01_SAFE_TO_USE_OMP_SIMD 1
34#endif
35
36// Workaround 02: clang.
37//
38// Clang 6+ generates incorrect code with OMP_SIMD in some particular cases.
39// Unlike CLANG_WA_01_SAFE_TO_USE_OMP_SIMD, the issue happens even with -O3.
40#if (defined __clang_major__) && (__clang_major__ >= 6)
41#define CLANG_WA_02_SAFE_TO_USE_OMP_SIMD 0
42#else
43#define CLANG_WA_02_SAFE_TO_USE_OMP_SIMD 1
44#endif
45
46// Workaround 03: GCC
47//
48// For very large functions with too much control flow (i.e. if, switch, goto
49// statements), GCC 7 may struggle to perform optimizations based on tree
50// dominator (i.e. -ftree-dominator-opts, which is enabled with O1), thereby
51// producing an internal compiler error (ICE). Specifically, it seems that the
52// jump threading optimization is the culprit, which cannot be disabled on its
53// own. There is no reliable way to reproduce the ICE, therefore it is not clear
54// which __GCC_MINOR__ version fixes issue.
55#if (defined __GNUC__) && (__GNUC__ == 7) && (!defined(__INTEL_COMPILER)) \
56 && (!defined(__clang__major__))
57#define GCC_WA_NO_TREE_DOMINATOR_OPTS 1
58#else
59#define GCC_WA_NO_TREE_DOMINATOR_OPTS 0
60#endif
61
62// Workaround 04: GCC
63//
64// GCC 10 & 11 (at least versiona 10.1, 10.3 & 11.1) report false positives
65// in xbyak when -Warray-bounds build setting is on
66#if (!defined(__INTEL_COMPILER) && !defined(__clang__major__)) \
67 && (defined(__GNUC__) && (__GNUC__ == 10 || __GNUC__ == 11))
68#pragma GCC diagnostic ignored "-Warray-bounds"
69#endif
70
71#endif // COMPILER_WORKAROUNDS_HPP
72