https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104839

            Bug ID: 104839
           Summary: ppc64 regression of GCC 12: conditional long += long
                    becomes unconditional SUBFC
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vstinner at redhat dot com
  Target Milestone: ---

Created attachment 52583
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52583&action=edit
bug4.c: reproducer

When attached bug4.c is built on ppc64 with -O1, it returns 1 (bug). With -O0,
it returns 0 (ok), as expected.

$ gcc bug4.c -o bug -O1 && ./bug; echo $?
1
$ gcc bug4.c -o bug -O0 && ./bug; echo $?
0
$ uname -m
ppc64le

On x86-64, it returns 0 (ok) with -O0 and -02 as expected.

If you replace "long t_5 = i" with "int t_5 = i", it works as expected: a
conditional machine code is generated for the conditional "t_5 += shape" C
code.

--

The reproducer comes from this Cython bug:
https://bugzilla.redhat.com/show_bug.cgi?id=2045160

Cython compiles reproducer.pyx as ~23 000 lines of C code. The bug is in the
generated __pyx_pf_11reproducer2_get_schar() function.

Extract of the original code:
---
  __pyx_t_5 = __pyx_v_i;
  __pyx_t_6 = __pyx_v_j;
  __pyx_t_7 = -1;
  if (__pyx_t_5 < 0) {
    __pyx_t_5 += __pyx_v_buf.shape[0];
    if (unlikely(__pyx_t_5 < 0)) __pyx_t_7 = 0;
  } else if (unlikely(__pyx_t_5 >= __pyx_v_buf.shape[0])) __pyx_t_7 = 0;
  if (__pyx_t_6 < 0) {
    __pyx_t_6 += __pyx_v_buf.shape[1];
    if (unlikely(__pyx_t_6 < 0)) __pyx_t_7 = 1;
  } else if (unlikely(__pyx_t_6 >= __pyx_v_buf.shape[1])) __pyx_t_7 = 1;
  if (unlikely(__pyx_t_7 != -1)) {
    __Pyx_RaiseBufferIndexError(__pyx_t_7);
    __PYX_ERR(0, 140, __pyx_L1_error)
  }
---

It took me 2 days to simply the code and remove dependencies to Cython and
Python.

Reply via email to