public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932
@ 2023-09-28 13:57 shaohua.li at inf dot ethz.ch
  2023-09-28 15:15 ` [Bug tree-optimization/111631] [14 Regression] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-09-28 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111631
           Summary: Wrong code at -Os on x86_64-linux-gnu since
                    r14-3217-g4d6132e5932
           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: rguenth at gcc dot gnu.org
  Target Milestone: ---

gcc at -Os produced the wrong code.

Bisected to r14-3217-g4d6132e5932

Compiler explorer: https://godbolt.org/z/Yj9bq1ecs

$ cat a.c
int printf(const char *, ...);
short a, f, i;
static const int *e;
short *g;
long h;
int main() {
  {
    unsigned j = i;
    a = 1;
    for (; a; a++) {
      {
        long b = j, d = h;
        int c = 0;
        while (d--)
          *(char *)b++ = c;
      }
      if (e)
        break;
    }
    j && (*g)--;
    const int **k = &e;
    *k = 0;
  }
  printf("%d\n", f);
}
$
$ gcc -O0 a.c && ./a.out
0
$ gcc -Os a.c && ./a.out
Segmentation fault
$ gcc -fsanitize=address,undefined a.c && ./a.out
0
$

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

* [Bug tree-optimization/111631] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932
  2023-09-28 13:57 [Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932 shaohua.li at inf dot ethz.ch
@ 2023-09-28 15:15 ` pinskia at gcc dot gnu.org
  2023-09-28 15:17 ` pinskia at gcc dot gnu.org
  2023-09-28 15:19 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-28 15:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
            Summary|Wrong code at -Os on        |[14 Regression] Wrong code
                   |x86_64-linux-gnu since      |at -Os on x86_64-linux-gnu
                   |r14-3217-g4d6132e5932       |since r14-3217-g4d6132e5932

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

* [Bug tree-optimization/111631] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932
  2023-09-28 13:57 [Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932 shaohua.li at inf dot ethz.ch
  2023-09-28 15:15 ` [Bug tree-optimization/111631] [14 Regression] " pinskia at gcc dot gnu.org
@ 2023-09-28 15:17 ` pinskia at gcc dot gnu.org
  2023-09-28 15:19 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ 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=111631

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Same underlying issue as PR 111583.

*** This bug has been marked as a duplicate of bug 111583 ***

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

* [Bug tree-optimization/111631] [14 Regression] Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932
  2023-09-28 13:57 [Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932 shaohua.li at inf dot ethz.ch
  2023-09-28 15:15 ` [Bug tree-optimization/111631] [14 Regression] " pinskia at gcc dot gnu.org
  2023-09-28 15:17 ` pinskia at gcc dot gnu.org
@ 2023-09-28 15:19 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-28 15:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
ldist produces:
  b_25 = (long int) j_23;
  d_26 = h;
  _8 = (sizetype) d_26;
  _38 = (char *) b_25;
  __builtin_memset (_38, 0, _8);

and also we have:
  <bb 7> [local count: 13370358]:
  if (j_23 != 0)
    goto <bb 10>; [50.00%]
  else
    goto <bb 11>; [50.00%]

...
  <bb 10> [local count: 6685179]:
  g.10_9 = g;
  _10 = *g.10_9;
  _11 = (unsigned short) _10;
  _12 = _11 + 65535;
  _13 = (short int) _12;
  *g.10_9 = _13;

But since d_26 is 0, originally there was no deferencing of _38 but now there
is and such.

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

end of thread, other threads:[~2023-09-28 15:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-28 13:57 [Bug tree-optimization/111631] New: Wrong code at -Os on x86_64-linux-gnu since r14-3217-g4d6132e5932 shaohua.li at inf dot ethz.ch
2023-09-28 15:15 ` [Bug tree-optimization/111631] [14 Regression] " pinskia at gcc dot gnu.org
2023-09-28 15:17 ` pinskia at gcc dot gnu.org
2023-09-28 15:19 ` pinskia 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).