public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
@ 2023-06-22 11:40 theodort at inf dot ethz.ch
  2023-06-22 12:58 ` [Bug tree-optimization/110361] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-22 11:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110361
           Summary: [13/14 Regression] Missed Dead Code Elimination when
                    using __builtin_unreachable since
                    r13-2020-g16b013c9d9b
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: theodort at inf dot ethz.ch
  Target Milestone: ---

https://godbolt.org/z/qab3679sq

Given the following code:

void foo(void);
static int a, b, d, p, k;
static int *c, *e, *g;
static short f;
static unsigned h;
static int **i = &c, **o = &g;
void __assert_fail() __attribute__((__noreturn__));
static void j(char, unsigned r) {
    h = r == 0 ?: 2 % r;
    int l = h;
    if (!(((l) >= 1) && ((l) <= 1))) {
        __builtin_unreachable();
    }
    int m;
    *i = &m;
}
static int *n();
static short q(short t) {
    *o = &p;
    return t;
}
static unsigned s() {
    int *j = n();
    if (e == 0 || e == &a || e == &d)
        ;
    else
        __assert_fail();
    return *j;
}
static int *n() {
    if (b) {
        if (c) __assert_fail();
        e = 0;
    }
    return &k;
}
int main() {
    j(q(s()), f);
    if (e == 0 || e == &a || e == &d)
        ;
    else
        foo();
    f = 0;
}

gcc-trunk -O2 does not eliminate the call to foo:

main:
        subq    $24, %rsp
        movq    e(%rip), %rax
        movswl  f(%rip), %edx
        testq   %rax, %rax
        je      .L2
        cmpq    $a, %rax
        je      .L4
        cmpq    $d, %rax
        jne     .L17
.L4:
        movq    $p, g(%rip)
        testl   %edx, %edx
        je      .L18
        leaq    12(%rsp), %rdx
        movq    %rdx, c(%rip)
        cmpq    $a, %rax
        je      .L5
        cmpq    $d, %rax
        je      .L5
        call    foo
.L5:
        xorl    %eax, %eax
        movw    %ax, f(%rip)
        xorl    %eax, %eax
        addq    $24, %rsp
        ret
.L18:
        leaq    12(%rsp), %rax
        movq    %rax, c(%rip)
        jmp     .L5
.L2:
        movq    $p, g(%rip)
        leaq    12(%rsp), %rax
        movq    %rax, c(%rip)
        jmp     .L5
.L17:
        xorl    %eax, %eax
        call    __assert_fail

gcc-12.3.0 -O2 eliminates the call to foo:

main:
        subq    $24, %rsp
        movq    e(%rip), %rax
        testq   %rax, %rax
        je      .L2
        cmpq    $a, %rax
        je      .L2
        cmpq    $d, %rax
        jne     .L14
.L2:
        movq    $p, g(%rip)
        leaq    12(%rsp), %rax
        movq    %rax, c(%rip)
        xorl    %eax, %eax
        movw    %ax, f(%rip)
        xorl    %eax, %eax
        addq    $24, %rsp
        ret
.L14:
        xorl    %eax, %eax
        call    __assert_fail

Bisects to r13-2020-g16b013c9d9b

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

* [Bug tree-optimization/110361] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
  2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
@ 2023-06-22 12:58 ` rguenth at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-22 12:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.2
           Keywords|                            |missed-optimization

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

* [Bug tree-optimization/110361] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
  2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
  2023-06-22 12:58 ` [Bug tree-optimization/110361] " rguenth at gcc dot gnu.org
@ 2023-07-27  9:27 ` rguenth at gcc dot gnu.org
  2023-08-07  9:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

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

* [Bug tree-optimization/110361] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
  2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
  2023-06-22 12:58 ` [Bug tree-optimization/110361] " rguenth at gcc dot gnu.org
  2023-07-27  9:27 ` rguenth at gcc dot gnu.org
@ 2023-08-07  9:05 ` pinskia at gcc dot gnu.org
  2024-03-08 15:30 ` law at gcc dot gnu.org
  2024-05-21  9:16 ` [Bug tree-optimization/110361] [13/14/15 " jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07  9:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-07
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

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

What is interesting is we have:
```
  <bb 7> [local count: 525923045]:
  g = &p;
  f.0_18 = f;
  if (f.0_18 == 0)
    goto <bb 8>; [50.00%]
  else
    goto <bb 13>; [50.00%]

  <bb 9> [local count: 225485782]:
  g = &p;
  f.0_36 = f;
  if (f.0_36 == 0)
    goto <bb 8>; [50.00%]
  else
    goto <bb 13>; [50.00%]

```
Those bb's are exactly the same.

Their pred bbs are:
```
  <bb 3> [local count: 751619280]:
  if (e.4_19 == &a)
    goto <bb 9>; [30.00%]
  else
    goto <bb 4>; [70.00%]

  <bb 4> [local count: 526133498]:
  if (e.4_19 == &d)
    goto <bb 7>; [99.96%]
  else
    goto <bb 5>; [0.04%]
```

Their succ branch (that matters) is:
```
  <bb 13> [local count: 375914866]:
  c = &m;
  m ={v} {CLOBBER(eol)};
  _22 = e.4_19 == &d;
  _1 = e.4_19 == &a;
  _23 = _1 | _22;
  if (_23 != 0)
    goto <bb 12>; [25.16%]
  else
    goto <bb 10>; [74.84%]
```

So coming into bb13, we know that `(e.4_19 == &d) | (e.4_19 == &a)` is true.
Removing the branch to bb 10 which was the call to foo:
  <bb 10> [local count: 281323581]:
  foo ();

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

* [Bug tree-optimization/110361] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
  2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-08-07  9:05 ` pinskia at gcc dot gnu.org
@ 2024-03-08 15:30 ` law at gcc dot gnu.org
  2024-05-21  9:16 ` [Bug tree-optimization/110361] [13/14/15 " jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:30 UTC (permalink / raw)
  To: gcc-bugs

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

Jeffrey A. Law <law at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
                 CC|                            |law at gcc dot gnu.org

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

* [Bug tree-optimization/110361] [13/14/15 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b
  2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2024-03-08 15:30 ` law at gcc dot gnu.org
@ 2024-05-21  9:16 ` jakub at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.

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

end of thread, other threads:[~2024-05-21  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-22 11:40 [Bug tree-optimization/110361] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-2020-g16b013c9d9b theodort at inf dot ethz.ch
2023-06-22 12:58 ` [Bug tree-optimization/110361] " rguenth at gcc dot gnu.org
2023-07-27  9:27 ` rguenth at gcc dot gnu.org
2023-08-07  9:05 ` pinskia at gcc dot gnu.org
2024-03-08 15:30 ` law at gcc dot gnu.org
2024-05-21  9:16 ` [Bug tree-optimization/110361] [13/14/15 " jakub 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).