Bug 95172 - [11 Regression] wrong code at -O1 on x86_64-linux-gnu since r11-272-gb6ff3ddecfa93d53
Summary: [11 Regression] wrong code at -O1 on x86_64-linux-gnu since r11-272-gb6ff3dde...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 11.0
: P1 normal
Target Milestone: 11.0
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks: 57359
  Show dependency treegraph
 
Reported: 2020-05-17 05:48 UTC by Qirun Zhang
Modified: 2020-05-18 09:50 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 10.1.0
Known to fail: 11.0
Last reconfirmed: 2020-05-18 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Qirun Zhang 2020-05-17 05:48:01 UTC
Recent regression. Bisection points to g:b6ff3ddecfa93d53867afaaa078f85f


$ gcc-trunk -v
gcc version 11.0.0 20200516 (experimental) [master revision 53b4d52f114:91c1d944166:f5b461d453043c6b6dda50db0439e4c78b241f03] (GCC)

$ gcc-trunk -O1 abc.c ; ./a.out
1

$ gcc-trunk  abc.c ; ./a.out
0

$ cat abc.c
int a, d;
int *b = &a;
short c;
int main() {
  for (; c <= 4; c--) {
    for (; d;)
      ;
    a = 1;
    *b = 0;
  }
  printf("%d\n", a);
}
Comment 1 Martin Liška 2020-05-18 05:56:00 UTC
Confirmed.
Comment 2 Richard Biener 2020-05-18 06:26:50 UTC
Mine.
Comment 3 GCC Commits 2020-05-18 09:50:01 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:52a0f83980082c9995f2d8ec9b88548520fb8a5f

commit r11-450-g52a0f83980082c9995f2d8ec9b88548520fb8a5f
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 18 09:17:24 2020 +0200

    tree-optimization/95172 - avoid mixing conditionalized and ordered SM
    
    The following testcase shows a missed optimization that then leads to
    wrong-code when issueing SMed stores on exits.  When we were able to
    compute an ordered sequence of stores for an exit we need to emit
    that in the correct order and we can emit it disregarding to any
    conditional for whether a store actually happened (we know it did).
    We can also improve detection as of whether we need conditional
    processing at all.  Both parts fix the testcase.
    
    2020-05-18  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/95172
            * tree-ssa-loop-im.c (execute_sm): Get flag whether we
            eventually need the conditional processing.
            (execute_sm_exit): When processing an orderd sequence
            avoid doing any conditional processing.
            (hoist_memory_references): Pass down whether all edges
            have ordered processing for a ref to execute_sm.
    
            * gcc.dg/torture/pr95172.c: New testcase.
Comment 4 Richard Biener 2020-05-18 09:50:22 UTC
Fixed.