public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
@ 2023-09-25  7:24 shaohua.li at inf dot ethz.ch
  2023-09-25  7:27 ` [Bug tree-optimization/111583] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-25  7:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111583
           Summary: [13/14 Regression] Wrong code at -Os on
                    x86_64-linux-gnu since r13-3281-g6cc3394507
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
                CC: amacleod at redhat dot com
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r13-3281-g6cc3394507

Compiler explorer: https://godbolt.org/z/8GM9YvMKb

$ cat a.c
int printf(const char *, ...);
int b, c, d;
char e;
short f;
const unsigned short **g;
char h(char k) {
  if (k)
    return '0';
  return 0;
}
int l() {
  b = 0;
  return 1;
}
static short m(unsigned k) {
  const unsigned short *n[65];
  g = &n[4];
  k || l();
  long a = k;
  char i = 0;
  unsigned long j = k;
  while (j--)
    *(char *)a++ = i;
  c = h(d);
  f = k;
  return 0;
}
int main() {
  long o = (e < 0) << 5;
  m(o);
  printf("%d\n", f);
}
$
$ gcc -O0 -fsanitize=address,undefined a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
32
$

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

* [Bug tree-optimization/111583] [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
@ 2023-09-25  7:27 ` pinskia at gcc dot gnu.org
  2023-09-25  7:46 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25  7:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.3

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

* [Bug tree-optimization/111583] [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
  2023-09-25  7:27 ` [Bug tree-optimization/111583] " pinskia at gcc dot gnu.org
@ 2023-09-25  7:46 ` pinskia at gcc dot gnu.org
  2023-09-28 15:17 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-25  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-09-25

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

The problem is a latent bug in ldist.
It turns:
```
  <bb 5> [local count: 955630224]:
  a_5 = a_4 + 1;
  a.4_6 = (char *) a_4;
  *a.4_6 = 0;

  <bb 6> [local count: 1073741824]:
  # a_4 = PHI <a_2(4), a_5(5)>
  # j_7 = PHI <j_3(4), j_8(5)>
  j_8 = j_7 + 18446744073709551615;
  if (j_7 != 0)
    goto <bb 5>; [89.00%]
  else
    goto <bb 7>; [11.00%]
```

Into:
```
  a_2 = (long int) k_1(D);
  j_3 = (long unsigned int) k_1(D);
  _23 = (sizetype) k_1(D);
  _25 = (char *) a_2;
  __builtin_memset (_25, 0, _23);
```

Which then basically says k!=0 as _25 can't be a null pointer.

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

* [Bug tree-optimization/111583] [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
  2023-09-25  7:27 ` [Bug tree-optimization/111583] " pinskia at gcc dot gnu.org
  2023-09-25  7:46 ` pinskia at gcc dot gnu.org
@ 2023-09-28 15:17 ` pinskia at gcc dot gnu.org
  2023-09-29  9:05 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-28 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 111631 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/111583] [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-09-28 15:17 ` pinskia at gcc dot gnu.org
@ 2023-09-29  9:05 ` rguenth at gcc dot gnu.org
  2023-09-29  9:50 ` 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 @ 2023-09-29  9:05 UTC (permalink / raw)
  To: gcc-bugs

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

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 #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
A conservative fix would be to make sure the memory accesses for the
memset/memcpy recognition are before the loop exit.  Note since -Os disables
loop header copying in most cases this will remove quite a bit of memset/memcpy
loop detection there.  The alternative would be to guard the calls.

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

* [Bug tree-optimization/111583] [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-09-29  9:05 ` rguenth at gcc dot gnu.org
@ 2023-09-29  9:50 ` cvs-commit at gcc dot gnu.org
  2023-09-29 10:02 ` [Bug tree-optimization/111583] [13 " 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 @ 2023-09-29  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS 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:962ca7149d652e4077a2259886e5cd2ea3cea0ab

commit r14-4329-g962ca7149d652e4077a2259886e5cd2ea3cea0ab
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 29 11:08:18 2023 +0200

    tree-optimization/111583 - loop distribution issue

    The following conservatively fixes loop distribution to only
    recognize memset/memcpy and friends when at least one element
    is going to be processed.  This avoids having an unconditional
    builtin call in the IL that might imply the source and destination
    pointers are non-NULL when originally pointers were not always
    dereferenced.

    With -Os loop header copying is less likely to ensure this.

            PR tree-optimization/111583
            * tree-loop-distribution.cc (find_single_drs): Ensure the
            load/store are always executed.

            * gcc.dg/tree-ssa/pr111583-1.c: New testcase.
            * gcc.dg/tree-ssa/pr111583-2.c: Likewise.

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

* [Bug tree-optimization/111583] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-09-29  9:50 ` cvs-commit at gcc dot gnu.org
@ 2023-09-29 10:02 ` rguenth at gcc dot gnu.org
  2023-09-29 10:02 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-29 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[13/14 Regression] Wrong    |[13 Regression] Wrong code
                   |code at -Os on              |at -Os on x86_64-linux-gnu
                   |x86_64-linux-gnu since      |since r13-3281-g6cc3394507
                   |r13-3281-g6cc3394507        |
      Known to fail|                            |13.2.0
      Known to work|                            |14.0

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk.  The issue is latent for longer but at least pre-ranger we
probably were not good enough to extract range info from this.

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

* [Bug tree-optimization/111583] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2023-09-29 10:02 ` [Bug tree-optimization/111583] [13 " rguenth at gcc dot gnu.org
@ 2023-09-29 10:02 ` rguenth at gcc dot gnu.org
  2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
  2023-11-10 14:27 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-29 10:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

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

* [Bug tree-optimization/111583] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2023-09-29 10:02 ` rguenth at gcc dot gnu.org
@ 2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
  2023-11-10 14:27 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-11-10 14:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

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

commit r13-8041-gb28be88c311f1bc4c62309906177ab3d97800deb
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 29 11:08:18 2023 +0200

    tree-optimization/111583 - loop distribution issue

    The following conservatively fixes loop distribution to only
    recognize memset/memcpy and friends when at least one element
    is going to be processed.  This avoids having an unconditional
    builtin call in the IL that might imply the source and destination
    pointers are non-NULL when originally pointers were not always
    dereferenced.

    With -Os loop header copying is less likely to ensure this.

            PR tree-optimization/111583
            * tree-loop-distribution.cc (find_single_drs): Ensure the
            load/store are always executed.

            * gcc.dg/tree-ssa/pr111583-1.c: New testcase.
            * gcc.dg/tree-ssa/pr111583-2.c: Likewise.

    (cherry picked from commit 962ca7149d652e4077a2259886e5cd2ea3cea0ab)

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

* [Bug tree-optimization/111583] [13 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507
  2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
                   ` (7 preceding siblings ...)
  2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
@ 2023-11-10 14:27 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-10 14:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
      Known to work|                            |13.2.1
             Status|ASSIGNED                    |RESOLVED

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

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

end of thread, other threads:[~2023-11-10 14:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25  7:24 [Bug tree-optimization/111583] New: [13/14 Regression] Wrong code at -Os on x86_64-linux-gnu since r13-3281-g6cc3394507 shaohua.li at inf dot ethz.ch
2023-09-25  7:27 ` [Bug tree-optimization/111583] " pinskia at gcc dot gnu.org
2023-09-25  7:46 ` pinskia at gcc dot gnu.org
2023-09-28 15:17 ` pinskia at gcc dot gnu.org
2023-09-29  9:05 ` rguenth at gcc dot gnu.org
2023-09-29  9:50 ` cvs-commit at gcc dot gnu.org
2023-09-29 10:02 ` [Bug tree-optimization/111583] [13 " rguenth at gcc dot gnu.org
2023-09-29 10:02 ` rguenth at gcc dot gnu.org
2023-11-10 14:24 ` cvs-commit at gcc dot gnu.org
2023-11-10 14:27 ` 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).