public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/109546] New: [13 Regression]  Missed Dead Code Elimination when using __builtin_unreachable
@ 2023-04-18 15:07 theodort at inf dot ethz.ch
  2023-04-19  7:58 ` [Bug tree-optimization/109546] [13/14 " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-04-18 15:07 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109546
           Summary: [13 Regression]  Missed Dead Code Elimination when
                    using __builtin_unreachable
           Product: gcc
           Version: 13.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: ---

cat input.c 

void foo(void);
static int a, c;
static int *b = &a;
static int **d = &b;
void __assert_fail() __attribute__((__noreturn__));
int main() {
  int *e = *d;
  if (e == &a || e == &c);
  else {
  __assert_fail();
  }
  if (e == &a || e == &c);
  else
    foo();
}

both gcc 12 and trunk at -O3 generate the following code:

main:
        movq    b(%rip), %rax
        cmpq    $c, %rax
        je      .L2
        cmpq    $a, %rax
        jne     .L7
.L2:
        xorl    %eax, %eax
        ret
.L7:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail
b:
        .quad   a

the call to foo is eliminated but the call to __assert_fail is missed, even
though 
both if statement conditions are identical. 

If add a __builtin_unreachable before the call to __assert_fail the opposite
happens:

void foo(void);
static int a, c;
static int *b = &a;
static int **d = &b;
void assert_fail() __attribute__((__noreturn__));
int main() {
  int *e = *d;
  if (e == &a || e == &c);
  else {
    __builtin_unreachable(); 
  assert_fail();
  }
  if (e == &a || e == &c);
  else
    foo();
}

gcc-trunk -O3 generates:

main:
        movq    b(%rip), %rax
        cmpq    $c, %rax
        je      .L4
        cmpq    $a, %rax
        je      .L4
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        ret
.L4:
        xorl    %eax, %eax
        ret
b:
        .quad   a

the call to __assert_fail is now properly eliminated but now the call to foo is
missed. 

This is a regression as gcc-12 generates: 

main:
        xorl    %eax, %eax
        ret

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

end of thread, other threads:[~2023-09-17  4:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-18 15:07 [Bug tree-optimization/109546] New: [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable theodort at inf dot ethz.ch
2023-04-19  7:58 ` [Bug tree-optimization/109546] [13/14 " rguenth at gcc dot gnu.org
2023-04-20 13:03 ` [Bug tree-optimization/109546] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-3596-ge7310e24b1c0ca marxin at gcc dot gnu.org
2023-04-21 18:52 ` amacleod at redhat dot com
2023-04-21 18:55 ` amacleod at redhat dot com
2023-04-21 19:18 ` amacleod at redhat dot com
2023-04-21 20:34 ` cvs-commit at gcc dot gnu.org
2023-04-26  6:58 ` rguenth at gcc dot gnu.org
2023-07-27  9:25 ` rguenth at gcc dot gnu.org
2023-09-17  4:10 ` 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).