public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu
@ 2024-06-21 12:42 zhendong.su at inf dot ethz.ch
  2024-06-21 12:43 ` [Bug tree-optimization/115579] " sjames at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2024-06-21 12:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115579
           Summary: wrong code at -Os with "-fno-tree-sra" on
                    x86_64-linux-gnu
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhendong.su at inf dot ethz.ch
  Target Milestone: ---

It appears to be a very recent regression as it doesn't reproduce with 14.1. 

Compiler Explorer: https://godbolt.org/z/8qsq5zbeE


[572] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240620 (experimental) (GCC) 
[573] % 
[573] % gcctk -Os small.c; ./a.out
[574] % 
[574] % gcctk -Os -fno-tree-sra small.c
[575] % ./a.out
Aborted
[576] % 
[576] % cat small.c
int printf(const char *, ...);
int a, b = 1, c;
int main() {
  int d[2], *e = &d[1];
  while (a) {
    int *f = &b;
    d[1] = 0;
    *f = 0;
  }
  if (c)
    printf("%d\n", *e);
  if (b != 1)
    __builtin_abort();
  return 0;
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2024-06-21 12:43 ` sjames at gcc dot gnu.org
  2024-06-21 12:44 ` [Bug tree-optimization/115579] [15 regression] " sjames at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-21 12:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Sam James <sjames at gcc dot gnu.org> ---
*** Bug 115578 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-06-21 12:43 ` [Bug tree-optimization/115579] " sjames at gcc dot gnu.org
@ 2024-06-21 12:44 ` sjames at gcc dot gnu.org
  2024-06-21 13:49 ` [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6 sjames at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-21 12:44 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong code at -Os with      |[15 regression] wrong code
                   |"-fno-tree-sra" on          |at -Os with "-fno-tree-sra"
                   |x86_64-linux-gnu            |on x86_64-linux-gnu
            Version|unknown                     |15.0
   Target Milestone|---                         |15.0
                 CC|                            |sjames at gcc dot gnu.org
           Keywords|                            |wrong-code

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-06-21 12:43 ` [Bug tree-optimization/115579] " sjames at gcc dot gnu.org
  2024-06-21 12:44 ` [Bug tree-optimization/115579] [15 regression] " sjames at gcc dot gnu.org
@ 2024-06-21 13:49 ` sjames at gcc dot gnu.org
  2024-06-21 16:36 ` zhendong.su at inf dot ethz.ch
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-21 13:49 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org
            Summary|[15 regression] wrong code  |[15 regression] wrong code
                   |at -Os with "-fno-tree-sra" |at -Os with "-fno-tree-sra"
                   |on x86_64-linux-gnu         |on x86_64-linux-gnu since
                   |                            |r15-1391-g4b75ed33fa5fd6

--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
very recent indeed: r15-1391-g4b75ed33fa5fd6

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2024-06-21 13:49 ` [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6 sjames at gcc dot gnu.org
@ 2024-06-21 16:36 ` zhendong.su at inf dot ethz.ch
  2024-06-21 16:43 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2024-06-21 16:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
Perhaps the same or a related issue.  It reproduces for -O{s,2,3}. 

Compiler Explorer: https://godbolt.org/z/x779P9b5a

[570] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20240620 (experimental) (GCC) 
[571] % 
[571] % gcctk -O2 small.c; ./a.out
[572] % 
[572] % gcctk -O2 -fno-tree-fre -fno-tree-sra -fno-tree-ch -fno-tree-dce
small.c
[573] % ./a.out
Floating point exception
[574] % 
[574] % cat small.c
int a = 1;
int main() {
  int b[1], c;
  for (c = 0; c < 2; c++) {
    int d = a, e = 1 / d;
    while (!e) {
      b[0] = 0;
      while (b[0])
        ;
      a = 0;
    }
  }
  return 0;
}

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-06-21 16:36 ` zhendong.su at inf dot ethz.ch
@ 2024-06-21 16:43 ` pinskia at gcc dot gnu.org
  2024-06-21 16:45 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-21 16:43 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-21
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed. LIM is doing it wrong:
```
  <bb 2> [local count: 118111600]:
  a.0_1 = a;
...
  b_lsm.10_17 = _16(D);
  goto <bb 4>; [100.00%]
...
  <bb 4> [local count: 1073741824]:
  # d_I_lsm.9_13 = PHI <d_I_lsm.9_15(2), d_I_lsm.9_18(3)>
  # b_lsm.10_14 = PHI <b_lsm.10_17(2), b_lsm.10_19(3)>
  if (a.0_1 != 0)
    goto <bb 3>; [89.00%]
  else
    goto <bb 5>; [11.00%]

  <bb 5> [local count: 118111600]:
  # d_I_lsm.9_23 = PHI <d_I_lsm.9_13(4)>
  # b_lsm.10_24 = PHI <b_lsm.10_14(4)>
  d[1] = d_I_lsm.9_23;
  b = b_lsm.10_24;
...
```

Why was the store to b an unconditional one here?



Before LIM:
```
  <bb 2> [local count: 118111600]:
  goto <bb 4>; [100.00%]

  <bb 3> [local count: 955630224]:
  d[1] = 0;
  b = 0;

  <bb 4> [local count: 1073741824]:
  a.0_1 = a;
  if (a.0_1 != 0)
    goto <bb 3>; [89.00%]
  else
    goto <bb 5>; [11.00%]
```

It looks like it is pulling out d[1] of the loop unconditionally and that also
causes b to be done unconditionally ...

So -Os is needed because we can't see the loop is an infinite one too ...

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2024-06-21 16:43 ` pinskia at gcc dot gnu.org
@ 2024-06-21 16:45 ` pinskia at gcc dot gnu.org
  2024-06-21 16:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-21 16:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Zhendong Su from comment #3)
> Perhaps the same or a related issue.  It reproduces for -O{s,2,3}. 

It is the same due to -fno-tree-ch . -Os has a very restrictive version of
that.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2024-06-21 16:45 ` pinskia at gcc dot gnu.org
@ 2024-06-21 16:58 ` pinskia at gcc dot gnu.org
  2024-06-22 12:28 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-21 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So looking into the code. The problem is the ordering.
That is if the store to b is first things will just work.

The loop to call execute_sm:
          execute_sm (loop, ref, aux_map, true, !first_p);

Except use_other_flag_var is wrong if the first one didn't have a store flag.

  if (multi_threaded_model_p && !use_other_flag_var)
    aux->store_flag
      = execute_sm_if_changed_flag_set (loop, ref, &aux->flag_bbs);
  else
    aux->store_flag = NULL_TREE;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2024-06-21 16:58 ` pinskia at gcc dot gnu.org
@ 2024-06-22 12:28 ` rguenth at gcc dot gnu.org
  2024-06-22 12:58 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-22 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Mine.  This is probably a latent issue.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (7 preceding siblings ...)
  2024-06-22 12:28 ` rguenth at gcc dot gnu.org
@ 2024-06-22 12:58 ` rguenth at gcc dot gnu.org
  2024-06-23  9:24 ` cvs-commit at gcc dot gnu.org
  2024-06-23  9:24 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-22 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, ok - the situation is new in that store-flag re-use is only considered for
loops which have all stores in a single BB and of course there always_stored
is always the same but now ref_can_have_store_data_races can be different for
stores.

I have a fix, it's to some extent not optimal as we emit unnecessary loads
up to the first var that needs the MT model.

There's the general optimization opportunity missing to share flag vars
for stores that are stored in the same BBs.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (8 preceding siblings ...)
  2024-06-22 12:58 ` rguenth at gcc dot gnu.org
@ 2024-06-23  9:24 ` cvs-commit at gcc dot gnu.org
  2024-06-23  9:24 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-23  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:8a1795bddcd34284936af4706f762d89c60fc69c

commit r15-1564-g8a1795bddcd34284936af4706f762d89c60fc69c
Author: Richard Biener <rguenther@suse.de>
Date:   Sat Jun 22 14:59:09 2024 +0200

    tree-optimization/115579 - fix wrong code with store-motion

    The recent change to relax store motion for variables that cannot have
    store data races broke the optimization to share flag vars for stores
    that all happen in the same single BB.  The following fixes this.

            PR tree-optimization/115579
            * tree-ssa-loop-im.cc (execute_sm): Return the auxiliary data
            created.
            (hoist_memory_references): Record the flag var that's eventually
            created and re-use it when all stores are in the same BB.

            * gcc.dg/pr115579.c: New testcase.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6
  2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (9 preceding siblings ...)
  2024-06-23  9:24 ` cvs-commit at gcc dot gnu.org
@ 2024-06-23  9:24 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-23  9:24 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-06-23  9:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-21 12:42 [Bug tree-optimization/115579] New: wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2024-06-21 12:43 ` [Bug tree-optimization/115579] " sjames at gcc dot gnu.org
2024-06-21 12:44 ` [Bug tree-optimization/115579] [15 regression] " sjames at gcc dot gnu.org
2024-06-21 13:49 ` [Bug tree-optimization/115579] [15 regression] wrong code at -Os with "-fno-tree-sra" on x86_64-linux-gnu since r15-1391-g4b75ed33fa5fd6 sjames at gcc dot gnu.org
2024-06-21 16:36 ` zhendong.su at inf dot ethz.ch
2024-06-21 16:43 ` pinskia at gcc dot gnu.org
2024-06-21 16:45 ` pinskia at gcc dot gnu.org
2024-06-21 16:58 ` pinskia at gcc dot gnu.org
2024-06-22 12:28 ` rguenth at gcc dot gnu.org
2024-06-22 12:58 ` rguenth at gcc dot gnu.org
2024-06-23  9:24 ` cvs-commit at gcc dot gnu.org
2024-06-23  9:24 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).