public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110413] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-1880-g827e208fa64
@ 2023-06-26 15:00 theodort at inf dot ethz.ch
  2023-06-27  6:31 ` [Bug tree-optimization/110413] " 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-26 15:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110413
           Summary: [14 Regression] Missed Dead Code Elimination when
                    using __builtin_unreachable since
                    r14-1880-g827e208fa64
           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/75vvarEvs

Given the following code:

void foo(void);
static int a, b, d, e, g, h;
static short f;
static int *i, *k;
static int **l = &i;
void __assert_fail(char *, char *, int, char *) __attribute__((__noreturn__));
static int(c)() { return a + b; }
static int *j() {
    f | e & 4073709551611 && c();
    return &d;
}
int main() {
    *l = j();
    h = 5;
    for (; h; h--) {
        k = j();
        if (k && k <= &d)
            ;
        else {
            __builtin_unreachable();
            __assert_fail("", "", 0, __PRETTY_FUNCTION__);
        }
    }
    if (k || k == &g)
        ;
    else
        foo();
    ;
}

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

j:
        movl    $d, %eax
        ret


main:
        subq    $8, %rsp
        movl    $0, %eax
        call    j
        movq    %rax, i(%rip)
        movq    %rax, k(%rip)
        movl    $0, h(%rip)
        cmpq    $g, %rax
        je      .L3
        testq   %rax, %rax
        je      .L5
.L3:
        movl    $0, %eax
        addq    $8, %rsp
        ret
.L5:
        call    foo
        jmp     .L3

gcc-13.1.0 -O1 eliminates the call to foo:

j:
        movl    $d, %eax
        ret


main:
        movl    $0, %eax
        call    j
        movq    %rax, i(%rip)
        movq    %rax, k(%rip)
        movl    $0, h(%rip)
        movl    $0, %eax
        ret

Bisects to r14-1880-g827e208fa64

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

end of thread, other threads:[~2024-05-07  7:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26 15:00 [Bug tree-optimization/110413] New: [14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r14-1880-g827e208fa64 theodort at inf dot ethz.ch
2023-06-27  6:31 ` [Bug tree-optimization/110413] " rguenth at gcc dot gnu.org
2023-06-27  9:34 ` rguenth at gcc dot gnu.org
2023-09-02 20:52 ` pinskia at gcc dot gnu.org
2024-03-08 15:30 ` law at gcc dot gnu.org
2024-05-07  7:40 ` [Bug tree-optimization/110413] [14/15 " rguenth 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).