public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu
@ 2024-06-07 19:16 zhendong.su at inf dot ethz.ch
  2024-06-07 23:50 ` [Bug middle-end/115388] [15 Regression] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: zhendong.su at inf dot ethz.ch @ 2024-06-07 19:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115388
           Summary: wrong code at -O3 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: ---

This appears to be a recent regression as it doesn't reproduce with 14.1 and
earlier.

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

[515] % 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 20240607 (experimental) (GCC) 
[516] % 
[516] % gcctk -O2 small.c; ./a.out
[517] % gcctk -O3 small.c
[518] % ./a.out
Aborted
[519] % cat small.c
int printf(const char *, ...);
int a[10], b, c, d[0], h, i, j, k, l;
char e = -1, g;
volatile int f;
static void n() {
  while (e >= 0)
    while (1)
      ;
  for (b = 2; b >= 0; b--) {
    for (k = 0; k < 4; k++) {
      if (e || i)
        continue;
      for (h = 0; h < 2; h++)
        f;
    }
    for (l = 2; l >= 0; l--)
      g = 0;
    for (; g < 1; g++)
      if (c)
        d[l] = 1;
    a[9] = 0;
    a[b] = 1;
    while (j)
      printf("\n");
  }
}
int main() {
  n();
  if (a[1] != 1)
    __builtin_abort();
  return 0;
}

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
@ 2024-06-07 23:50 ` pinskia at gcc dot gnu.org
  2024-06-09 12:37 ` [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7 sjames at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-07 23:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-06-07
           Keywords|                            |needs-bisection
          Component|tree-optimization           |middle-end
     Ever confirmed|0                           |1
            Summary|wrong code at -O3 on        |[15 Regression] wrong code
                   |x86_64-linux-gnu            |at -O3 on x86_64-linux-gnu
   Target Milestone|---                         |15.0
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-06-07 23:50 ` [Bug middle-end/115388] [15 Regression] " pinskia at gcc dot gnu.org
@ 2024-06-09 12:37 ` sjames at gcc dot gnu.org
  2024-06-10  6:35 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-09 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |rguenth at gcc dot gnu.org,
                   |                            |sjames at gcc dot gnu.org
            Summary|[15 Regression] wrong code  |[15 Regression] wrong code
                   |at -O3 on x86_64-linux-gnu  |at -O3 on x86_64-linux-gnu
                   |                            |since
                   |                            |r15-571-g1e0ae1f52741f7

--- Comment #2 from Sam James <sjames at gcc dot gnu.org> ---
r15-571-g1e0ae1f52741f7

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
  2024-06-07 23:50 ` [Bug middle-end/115388] [15 Regression] " pinskia at gcc dot gnu.org
  2024-06-09 12:37 ` [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7 sjames at gcc dot gnu.org
@ 2024-06-10  6:35 ` rguenth at gcc dot gnu.org
  2024-06-10  9:26 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-10  6:35 UTC (permalink / raw)
  To: gcc-bugs

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

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
            Version|unknown                     |15.0

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Ah, finally a small testcase.  I'll have a look.

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2024-06-10  6:35 ` rguenth at gcc dot gnu.org
@ 2024-06-10  9:26 ` rguenth at gcc dot gnu.org
  2024-06-10 11:36 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-10  9:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's DSE5 deleting

  Deleted dead store: a[b.19_216] = 1;

there's a big irreducible region following the loop with this store, but
I fail to see how we can reach the load without going through the other
redundant store.

Ah, wait - it's the same as with loops in irreducible regions and triggering
a latent issue.  We do

                      /* If we visit this PHI by following a backedge then we
                         have to make sure ref->ref only refers to SSA names
                         that are invariant with respect to the loop
                         represented by this PHI node.  */
                      if (dominated_by_p (CDI_DOMINATORS, gimple_bb (stmt),
                                          gimple_bb (use_stmt))
                          && !for_each_index (ref->ref ? &ref->ref :
&ref->base,
                                              check_name, gimple_bb
(use_stmt)))
                        return DSE_STORE_LIVE;

but we identify backedges by using dominators which only works for natural
loops and not irreducible regions.  We have to either disregard all refs in
irreducible regions or check for invariantness in the irreducible (sub-)region
spanned by the PHI and the backedge source.

I'm going to check the latter.

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-06-10  9:26 ` rguenth at gcc dot gnu.org
@ 2024-06-10 11:36 ` cvs-commit at gcc dot gnu.org
  2024-06-10 11:37 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-10 11:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 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:818e760528d436ea8f6c28ef620e2bb82d456ea1

commit r15-1163-g818e760528d436ea8f6c28ef620e2bb82d456ea1
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Jun 10 11:29:43 2024 +0200

    tree-optimization/115388 - wrong DSE in irreductible regions

    The following fixes a latent bug in DSE with regarding to variant
    array accesses where the code avoiding bogus DSE in loops fails to
    handle irreducible regions.  For those we need to make sure backedges
    are marked and discover a header for the irreducible region to check
    invariantness.

            PR tree-optimization/115388
            * tree-ssa-dse.cc (dse_classify_store): Handle irreducible
            regions.
            (pass_dse::execute): Make sure to mark backedges.

            * gcc.dg/torture/pr115388.c: New testcase.

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2024-06-10 11:36 ` cvs-commit at gcc dot gnu.org
@ 2024-06-10 11:37 ` rguenth at gcc dot gnu.org
  2024-06-10 14:31 ` wilco at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-10 11:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.  Unfortunately this didn't fix PR115256 if I checked correctly.  Keep
searching!

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2024-06-10 11:37 ` rguenth at gcc dot gnu.org
@ 2024-06-10 14:31 ` wilco at gcc dot gnu.org
  2024-06-10 14:38 ` pinskia at gcc dot gnu.org
  2024-06-10 15:27 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: wilco at gcc dot gnu.org @ 2024-06-10 14:31 UTC (permalink / raw)
  To: gcc-bugs

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

Wilco <wilco at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wilco at gcc dot gnu.org

--- Comment #7 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #6)
> Fixed.  Unfortunately this didn't fix PR115256 if I checked correctly.  Keep
> searching!

The testcase hangs on AArch64, so this commit didn't fix it...

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2024-06-10 14:31 ` wilco at gcc dot gnu.org
@ 2024-06-10 14:38 ` pinskia at gcc dot gnu.org
  2024-06-10 15:27 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-10 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Wilco from comment #7)
> (In reply to Richard Biener from comment #6)
> > Fixed.  Unfortunately this didn't fix PR115256 if I checked correctly.  Keep
> > searching!
> 
> The testcase hangs on AArch64, so this commit didn't fix it...

I suspect the issue is char being unsigned on a few targets. I will fix it in a
few hours.

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

* [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7
  2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
                   ` (7 preceding siblings ...)
  2024-06-10 14:38 ` pinskia at gcc dot gnu.org
@ 2024-06-10 15:27 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-06-10 15:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:c3d1153bc0a2b820e3c373ecf19a5a127703f854

commit r15-1165-gc3d1153bc0a2b820e3c373ecf19a5a127703f854
Author: Andrew Pinski <quic_apinski@quicinc.com>
Date:   Mon Jun 10 08:23:00 2024 -0700

    Fix pr115388.c: plain char could be unsigned by default [PR115415]

    This is a simple fix to the testcase as plain `char` could be
    unsigned by default on some targets (e.g. aarch64 and powerpc).

    Committed as obvious after quick test of the testcase on both aarch64 and
x86_64.

    gcc/testsuite/ChangeLog:

            PR testsuite/115415
            PR tree-optimization/115388
            * gcc.dg/torture/pr115388.c: Use `signed char` directly instead
            of plain `char`.

    Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>

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

end of thread, other threads:[~2024-06-10 15:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-07 19:16 [Bug tree-optimization/115388] New: wrong code at -O3 on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2024-06-07 23:50 ` [Bug middle-end/115388] [15 Regression] " pinskia at gcc dot gnu.org
2024-06-09 12:37 ` [Bug middle-end/115388] [15 Regression] wrong code at -O3 on x86_64-linux-gnu since r15-571-g1e0ae1f52741f7 sjames at gcc dot gnu.org
2024-06-10  6:35 ` rguenth at gcc dot gnu.org
2024-06-10  9:26 ` rguenth at gcc dot gnu.org
2024-06-10 11:36 ` cvs-commit at gcc dot gnu.org
2024-06-10 11:37 ` rguenth at gcc dot gnu.org
2024-06-10 14:31 ` wilco at gcc dot gnu.org
2024-06-10 14:38 ` pinskia at gcc dot gnu.org
2024-06-10 15:27 ` cvs-commit 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).