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

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).