Bug 91240

Summary: [8/9/10 Regression] Wrong code with -O3 due to unroll and jam pass
Product: gcc Reporter: Vsevolod Livinskii <vsevolod.livinskiy>
Component: tree-optimizationAssignee: Michael Matz <matz>
Status: RESOLVED DUPLICATE    
Severity: normal CC: dimhen, jakub, matz, regehr, rguenth
Priority: P2 Keywords: wrong-code
Version: 10.0   
Target Milestone: 8.4   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90796
Host: Target:
Build: Known to work: 7.4.0
Known to fail: 10.0, 8.3.0, 9.1.0 Last reconfirmed: 2019-07-24 00:00:00
Bug Depends on:    
Bug Blocks: 103035    

Description Vsevolod Livinskii 2019-07-23 21:20:19 UTC
GCC produces wrong code with -O3.

Reproducer:

#include <stdio.h>

long long a;
int b[96][76];
int c[81];

void d(long long *e, int p2) { *e ^= p2; }

int main() {
  for (int f = 0; f < 80; ++f)
    for (int g = 0; g < 76; ++g)
      b[f][g] = c[f] = 9094;

  for (int f = 6; f <= 9; f++)
    for (int g = 6; g <= 75; g++)
      if (b[0][g])
        c[f + 1] *= f + (unsigned)c[f];

  printf("%d\n", c[8]);
}

Error:
>$ gcc -O3 small.c ; ./a.out
1637288310
>$ gcc -O0 small.c ; ./a.out
-2106497818

GCC version is 10.0.0 (Rev: 273743)
Comment 1 Martin Liška 2019-07-24 07:07:25 UTC
Confirmed, started with Michael's r255467.
Comment 2 Michael Matz 2019-08-05 14:11:58 UTC
Mine.
Comment 3 Michael Matz 2019-08-05 20:00:27 UTC
Also fixed by the patch at PR90796.
Comment 4 Jakub Jelinek 2019-11-20 11:38:53 UTC
Dup.

*** This bug has been marked as a duplicate of bug 90796 ***