Bug 103615 - [9 Regression] wrong code with "-O3" or "-O1 -ftree-vectorize" on x86_64-pc-linux-gnu
Summary: [9 Regression] wrong code with "-O3" or "-O1 -ftree-vectorize" on x86_64-pc-l...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 9.3.0
: P2 normal
Target Milestone: 9.5
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2021-12-08 09:15 UTC by Siarhei Siamashka
Modified: 2022-01-08 10:55 UTC (History)
3 users (show)

See Also:
Host:
Target: X86_64
Build:
Known to work: 10.1.0, 7.3.0
Known to fail: 9.3.0
Last reconfirmed: 2021-12-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Siarhei Siamashka 2021-12-08 09:15:21 UTC
A reduced testcase from https://codeforces.com/blog/entry/97433

$ cat test.c
int z = 5;
int a[6] = {0, 0, 0, 0, 0, 1};
int main() {
  for (int x = 5; x; x--)
    for (int y = z; y >= x; y--)
      a[y - x] += a[y];
  if (a[0] != 7)
    __builtin_abort ();
  return 0;
}

$ gcc-7.3.0 -O3 test.c && ./a.out

$ gcc-8.3.0 -O3 test.c && ./a.out
Aborted

$ gcc-9.3.0 -O3 test.c && ./a.out
Aborted

$ gcc-9.4.1 -O3 test.c && ./a.out
Aborted

$ gcc-10.3.0 -O3 test.c && ./a.out

Only GCC versions 8.x and 9.x are affected and the bug is triggered by "-O3" or "-O1 -ftree-vectorize" optimization option.
Comment 1 Martin Liška 2021-12-08 09:21:42 UTC
Thanks for the report.
Using -march=core2 started with r8-5008-ga52206ae28ed3e55 and was fixed with r10-4758-ge9acf80c96d68191.
Comment 2 CVS Commits 2022-01-03 08:57:42 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:660e5834667a9efdb4d400dfb83caa48c9dd9f9b

commit r12-6175-g660e5834667a9efdb4d400dfb83caa48c9dd9f9b
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jan 3 09:56:13 2022 +0100

    Add testcase for PR103615
    
    This adds a testcase for a fixed wrong-code bug.
    
    2022-01-03  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/103615
            * gcc.dg/torture/pr103615.c: New testcase.