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

            Bug ID: 120254
           Summary: wrong code at -O3 on x86_64-pc-linux-gnu
           Product: gcc
           Version: 15.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhiyijie at zju dot edu.cn
  Target Milestone: ---

Created attachment 61416
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=61416&action=edit
test case

It produces wrong code when compiling using gcc-15.1.0 with -O3 option. I get
sum of array A as -1957771396 using -O0 and -O2, but 1793347916 using -O3.

This situation disappears when I lower the number of "N"(e.g., from 30 to 10),
and also when I add "-fno-tree-vectorize".


Here is the kernel function:
    #define N 30
    for (int i = 0; i < N - 1; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N - 1; k++) {
                A[k + 1][i][i] += A[k + 1][i][i + 1] - A[k][i][i] - 6;
            }
        }
    }

$ gcc-15 -O0 ./test.c -o ./test0
$ ./test0
-1957771396
$ gcc-15 -O3 ./test.c -o ./test3
$ ./test3
1793347916
$ gcc-15 -O3 -fno-tree-vectorize ./test.c -o ./test3_
$ ./test3_
-1957771396
$ gcc-15 -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.1.0 (GCC)

Reply via email to