public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
@ 2023-06-08 14:07 theodort at inf dot ethz.ch
  2023-06-08 14:09 ` [Bug tree-optimization/110173] " theodort at inf dot ethz.ch
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-08 14:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110173
           Summary: [14 Regression] Missed Dead Code Elimination when
                    using __builtin_unreachable since r14-569-g21e2ef2dc25
           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/ssja5dKdY


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


gcc-trunk -Os -S: 

main:
        movq    g(%rip), %rax
        testq   %rax, %rax
        je      .L2
        cmpq    $f, %rax
        je      .L2
.L3:
        pushq   %rsi
        xorl    %eax, %eax
        call    __assert_fail
.L2:
        xorl    %ecx, %ecx
        movl    %ecx, n(%rip)
        testq   %rax, %rax
        jne     .L3
        xorl    %edx, %edx
        movq    %rdx, g(%rip)
        ret


main:
        pushq   %rsi
        movq    g(%rip), %rax
        cmpq    $f, %rax
        je      .L2
        testq   %rax, %rax
        jne     .L13
.L2:
        xorl    %ecx, %ecx
        movl    %ecx, n(%rip)
        cmpq    $f, %rax
        je      .L3
        testq   %rax, %rax
        je      .L11
        call    foo
.L13:
        xorl    %eax, %eax
        call    __assert_fail
.L3:
        testq   %rax, %rax
        jne     .L13
.L11:
        xorl    %eax, %eax
        movq    %rax, g(%rip)
        xorl    %eax, %eax
        popq    %rdx
        ret


Bisects to r14-569-g21e2ef2dc25

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

* [Bug tree-optimization/110173] [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
@ 2023-06-08 14:09 ` theodort at inf dot ethz.ch
  2023-06-08 14:17 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-08 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Theodoros Theodoridis <theodort at inf dot ethz.ch> ---
*The first piece of ASM is generated by gcc 13.1, the second by gcc trunk

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

* [Bug tree-optimization/110173] [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
  2023-06-08 14:09 ` [Bug tree-optimization/110173] " theodort at inf dot ethz.ch
@ 2023-06-08 14:17 ` pinskia at gcc dot gnu.org
  2023-06-08 18:26 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 14:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm
static void i() { *h = j(); }
static int *j(unsigned o) {

I suspect this is just might be another one of these cases where a variable is
uninitialized gets a different value now.

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

* [Bug tree-optimization/110173] [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
  2023-06-08 14:09 ` [Bug tree-optimization/110173] " theodort at inf dot ethz.ch
  2023-06-08 14:17 ` pinskia at gcc dot gnu.org
@ 2023-06-08 18:26 ` pinskia at gcc dot gnu.org
  2023-06-08 18:41 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 18:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Hmm
> static void i() { *h = j(); }
> static int *j(unsigned o) {
> 
> I suspect this is just might be another one of these cases where a variable
> is uninitialized gets a different value now.

Yes it is definitely related to that variable being uninitialized.

if you replace o with either 1 or 0, the call to foo is there even in GCC 13.

I think this can be marked as a non-regression.

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

* [Bug tree-optimization/110173] [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-06-08 18:26 ` pinskia at gcc dot gnu.org
@ 2023-06-08 18:41 ` pinskia at gcc dot gnu.org
  2023-06-08 18:43 ` [Bug tree-optimization/110173] " pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 18:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So CCP2 now removes:
Removing dead stmt:iftmp.4_9 = PHI <1(5), 0(6)>

Which allows to remove all of this:
  <bb 5> [local count: 1073441178]:
  if (t_4(D) != 0)
    goto <bb 7>; [50.00%]
  else
    goto <bb 6>; [50.00%]

  <bb 6> [local count: 536720589]:

  <bb 7> [local count: 1073441178]:
  # iftmp.4_9 = PHI <1(5), 0(6)>

And then jump threading happens (threadfull1) but leaves behind some extra jump
threading it seems.
```
  <bb 3> [local count: 751619281]:
  if (g.1_6 == 0B)
    goto <bb 5>; [99.96%]
  else
    goto <bb 4>; [0.04%]

  <bb 5> [local count: 751318634]:
  n = 0;
  goto <bb 7>; [100.00%]

  <bb 7> [local count: 751408828]:
  if (g.1_6 == 0B)
    goto <bb 10>; [30.00%]
  else
    goto <bb 8>; [70.00%]
```
No other block can enter `bb 5`.

So not my issue.

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

* [Bug tree-optimization/110173] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-06-08 18:41 ` pinskia at gcc dot gnu.org
@ 2023-06-08 18:43 ` pinskia at gcc dot gnu.org
  2023-06-08 18:46 ` [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[14 Regression] Missed Dead |Missed Dead Code
                   |Code Elimination when using |Elimination when using
                   |__builtin_unreachable since |__builtin_unreachable since
                   |r14-569-g21e2ef2dc25        |r14-569-g21e2ef2dc25

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note initializing gives the same missing jump threading opportunity.

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

* [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-06-08 18:43 ` [Bug tree-optimization/110173] " pinskia at gcc dot gnu.org
@ 2023-06-08 18:46 ` pinskia at gcc dot gnu.org
  2023-06-19 12:05 ` theodort at inf dot ethz.ch
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-08 18:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Missed Dead Code            |[13/14 Regression] Missed
                   |Elimination when using      |Dead Code Elimination when
                   |__builtin_unreachable since |using __builtin_unreachable
                   |r14-569-g21e2ef2dc25        |
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-06-08
   Target Milestone|---                         |13.2

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
s/j();/j(0);/
Actually worked in GCC 12.3.0 but failed in GCC 13.1.0 so that is a regression
there.

But definitely unrelated to that GCC 14 change.

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

* [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2023-06-08 18:46 ` [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable pinskia at gcc dot gnu.org
@ 2023-06-19 12:05 ` theodort at inf dot ethz.ch
  2023-07-27  9:26 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-19 12:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Theodoros Theodoridis <theodort at inf dot ethz.ch> ---
The modified case (s/j();/j(0);/) bisects to r13-1934-g353fd1ec3df

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

* [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2023-06-19 12:05 ` theodort at inf dot ethz.ch
@ 2023-07-27  9:26 ` rguenth at gcc dot gnu.org
  2024-03-08 15:35 ` law at gcc dot gnu.org
  2024-05-21  9:15 ` [Bug tree-optimization/110173] [13/14/15 " jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 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] 11+ messages in thread

* [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (7 preceding siblings ...)
  2023-07-27  9:26 ` rguenth at gcc dot gnu.org
@ 2024-03-08 15:35 ` law at gcc dot gnu.org
  2024-05-21  9:15 ` [Bug tree-optimization/110173] [13/14/15 " jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-08 15:35 UTC (permalink / raw)
  To: gcc-bugs

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

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] 11+ messages in thread

* [Bug tree-optimization/110173] [13/14/15 Regression] Missed Dead Code Elimination when using __builtin_unreachable
  2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
                   ` (8 preceding siblings ...)
  2024-03-08 15:35 ` law at gcc dot gnu.org
@ 2024-05-21  9:15 ` jakub at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 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] 11+ messages in thread

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

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 14:07 [Bug tree-optimization/110173] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-569-g21e2ef2dc25 theodort at inf dot ethz.ch
2023-06-08 14:09 ` [Bug tree-optimization/110173] " theodort at inf dot ethz.ch
2023-06-08 14:17 ` pinskia at gcc dot gnu.org
2023-06-08 18:26 ` pinskia at gcc dot gnu.org
2023-06-08 18:41 ` pinskia at gcc dot gnu.org
2023-06-08 18:43 ` [Bug tree-optimization/110173] " pinskia at gcc dot gnu.org
2023-06-08 18:46 ` [Bug tree-optimization/110173] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable pinskia at gcc dot gnu.org
2023-06-19 12:05 ` theodort at inf dot ethz.ch
2023-07-27  9:26 ` rguenth at gcc dot gnu.org
2024-03-08 15:35 ` law at gcc dot gnu.org
2024-05-21  9:15 ` [Bug tree-optimization/110173] [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).