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

            Bug ID: 97960
           Summary: [8/9/10/11 Regression] Wrong code at -O3 since
                    r8-6511-g3ae129323d
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

GCC miscompiles the following C++ testcase at -O3 (reproduced on both x86 and
aarch64):

const int &c(const int &d, const int &f) {
  if (d < f)
    return f;
  return d;
}

short a[575];
unsigned b[25];
unsigned char g;
int main()
{
  for (int e = 0; e < 23; ++e)
    a[e * 23] = 16137;
  for (signed char h = c(g, 253) + 3; h < 24; h++)
    b[h] = 1064739102;
  for (int e = 0; e < 23; ++e)
    if (a[e * 23] != 16137)
      __builtin_abort();
}

When compiled with -O{0,g,s,1,2} (with or without -ftree-vectorize), the
program exits cleanly, but aborts when compiled with -O3 since the above
revision. The program also exits cleanly when compiled with clang on x86 and
aarch64 at various optimization levels.

Reply via email to