Bug 115697 - [12/13/14/15 Regression] Miscompilation with -fgraphite-identity at -O2 since r11-3917-g28290cb50c7dbf
Summary: [12/13/14/15 Regression] Miscompilation with -fgraphite-identity at -O2 since...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 15.0
: P3 normal
Target Milestone: 12.5
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: graphite
  Show dependency treegraph
 
Reported: 2024-06-28 10:14 UTC by Michael Orlitzky
Modified: 2024-07-31 02:18 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.5.0
Known to fail: 11.1.0
Last reconfirmed: 2024-06-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Orlitzky 2024-06-28 10:14:37 UTC
While debugging a test failure in the flint library (https://github.com/flintlib/flint/issues/2029), we seem to have discovered a miscompilation. Fredrik Johansson was able to come up with a minimal reproducer. This may be a duplicate of bug 47048, but having more reproducible test cases never hurts.

$ gcc-15 -O2 -Wall -Wextra main.c 
$ ./a.out 
6 4 1

$ gcc-15 -O2 -fgraphite-identity -Wall -Wextra main.c 
$ ./a.out 
3 2 1

$ cat main.c 
#include <stdio.h>

void
shift(long * c, long n)
{
    long i, j;

    if (n <= 62)
    {
        for (i = n - 2; i >= 0; i--)
            for (j = i; j < n - 1; j++)
                c[j] += c[j + 1];
    }
}

int main(void)
{
    long c[3];
    volatile long n = 3;
    c[0] = 3;
    c[1] = 2;
    c[2] = 1;
    shift(c, n);
    printf("%ld %ld %ld\n", c[0], c[1], c[2]);
}
Comment 1 Xi Ruoyao 2024-06-28 11:47:09 UTC
Confirmed.

- Code from GCC 6 - 10 outputs "6 4 1" correctly.
- Code from GCC 11 - 14 outputs "3 2 1".
- Code from GCC 5 crashes with SIGFPE.
Comment 2 Richard Biener 2024-07-19 13:25:49 UTC
GCC 11 branch is being closed.
Comment 3 Sam James 2024-07-31 02:18:17 UTC
r11-3917-g28290cb50c7dbf