8000 BUG: Disable -O3 on right_shift on compilers which emit an internal e… · numpy/numpy@6cf6ece · GitHub
[go: up one dir, main page]

Skip to content

Commit 6cf6ece

Browse files
committed
BUG: Disable -O3 on right_shift on compilers which emit an internal error
Needed to make CI pass
1 parent 79d7bc2 commit 6cf6ece

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

numpy/core/setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ def generate_config_h(ext, build_dir):
463463
rep = check_long_double_representation(config_cmd)
464464
moredefs.append(('HAVE_LDOUBLE_%s' % rep, 1))
465465

466+
if check_for_right_shift_internal_compiler_error(config_cmd):
467+
moredefs.append('NPY_DO_NOT_OPTIMIZE_LONG_right_shift')
468+
moredefs.append('NPY_DO_NOT_OPTIMIZE_ULONG_right_shift')
469+
moredefs.append('NPY_DO_NOT_OPTIMIZE_LONGLONG_right_shift')
470+
moredefs.append('NPY_DO_NOT_OPTIMIZE_ULONGLONG_right_shift')
471+
466472
# Py3K check
467473
if sys.version_info[0] == 3:
468474
moredefs.append(('NPY_PY3K', 1))

numpy/core/setup_common.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import warnings
66
import copy
77
import binascii
8+
import textwrap
89

910
from numpy.distutils.misc_util import mingw32
1011

@@ -414,3 +415,41 @@ def long_double_representation(lines):
414415
else:
415416
# We never detected the after_sequence
416417
raise ValueError("Could not lock sequences (%s)" % saw)
418+
419+
420+
def check_for_right_shift_internal_compiler_error(cmd):
421+
"""
422+
On our arm CI, this fails with an internal compilation error
423+
424+
The failure looks like the following, and can be reproduced on ARM64 GCC 5.4:
425+
426+
<source>: In function 'right_shift':
427+
<source>:4:20: internal compiler error: in expand_shift_1, at expmed.c:2349
428+
ip1[i] = ip1[i] >> in2;
429+
^
430+
Please submit a full bug report,
431+
with preprocessed source if appropriate.
432+
See <http://gcc.gnu.org/bugs.html> for instructions.
433+
Compiler returned: 1
434+
435+
This function returns True if this compiler bug is present, and we need to
436+
turn off optimization for the function
437+
"""
438+
cmd._check_compiler()
439+
has_optimize = cmd.try_compile(textwrap.dedent("""\
440+
__attribute__((optimize("O3"))) void right_shift() {}
441+
"""), None, None)
442+
if not has_optimize:
443+
return False
444+
445+
no_err = cmd.try_compile(textwrap.dedent("""\
446+
typedef long the_type; /* fails also for unsigned and long long */
447+
__attribute__((optimize("O3"))) void right_shift(the_type in2, the_type *ip1, int n) {
448+
for (int i = 0; i < n; i++) {
449+
if (in2 < (the_type)sizeof(the_type) * 8) {
450+
ip1[i] = ip1[i] >> in2;
451+
}
452+
}
453+
}
454+
"""), None, None)
455+
return not no_err

numpy/core/src/umath/loops.c.src

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,11 @@ NPY_NO_EXPORT NPY_GCC_OPT_3 void
828828
#undef INT_left_shift_needs_clear_floatstatus
829829
#undef UINT_left_shift_needs_clear_floatstatus
830830

831-
NPY_NO_EXPORT NPY_GCC_OPT_3 void
831+
NPY_NO_EXPORT
832+
#ifndef NPY_DO_NOT_OPTIMIZE_@TYPE@_right_shift
833+
NPY_GCC_OPT_3
834+
#endif
835+
void
832836
@TYPE@_right_shift@isa@(char **args, npy_intp *dimensions, npy_intp *steps,
833837
void *NPY_UNUSED(func))
834838
{

0 commit comments

Comments
 (0)
0