public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110327] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-4790-g4b3a325f07a
@ 2023-06-20 17:11 theodort at inf dot ethz.ch
  2023-06-21  8:33 ` [Bug tree-optimization/110327] " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-20 17:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110327
           Summary: [12/13/14 Regression] Missed Dead Code Elimination
                    when using __builtin_unreachable since
                    r12-4790-g4b3a325f07a
           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/eT1jqzrT5

Given the following code:

void foo(void);
static int a, c;
static int *d, *e = &a;
static int **f = &d, **g = &e;
static int ***h = &g;
static int ****i = &h;
static short j;
static char(k)(char b) {
    if (!(((b) >= -28) && ((b) <= -28))) {
        __builtin_unreachable();
    }
    return 0;
}
static int l() {
    a = -28;
    for (; a != 2; a++) {
        j = c;
        c = 0;
        for (; c != 2; c = j)
            if (a) break;
        k(****i);
        if (****i >= 5 ^ 1) {
            ***i = *f;
            if (c < 1) return 1;
            if (a) foo();
            ;
        }
    }
    return a;
}
int main() { l(); }

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

main:
        subq    $8, %rsp
        movl    $-28, %eax
        movl    $-28, a(%rip)
        .p2align 4,,10
        .p2align 3
.L10:
        movl    c(%rip), %edx
        testl   %eax, %eax
        jne     .L19
        cmpw    $2, %dx
        je      .L4
.L5:
        jmp     .L5
        .p2align 4,,10
        .p2align 3
.L4:
        movl    $2, c(%rip)
        movl    $2, %esi
.L3:
        movq    h(%rip), %rdx
        movq    (%rdx), %rdx
        movq    (%rdx), %rcx
        cmpl    $4, (%rcx)
        jg      .L7
        movq    d(%rip), %rcx
        movq    %rcx, (%rdx)
        testl   %esi, %esi
        je      .L16
        testl   %eax, %eax
        jne     .L20
.L7:
        movl    a(%rip), %eax
        addl    $1, %eax
        movl    %eax, a(%rip)
        cmpl    $2, %eax
        jne     .L10
.L16:
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
        .p2align 4,,10
        .p2align 3
.L20:
        call    foo
        jmp     .L7
.L19:
        xorl    %edx, %edx
        xorl    %esi, %esi
        movl    %edx, c(%rip)
        jmp     .L3

gcc-11.4.0 -O2 eliminates the call to foo:

main:
        movl    $-28, a(%rip)
        movq    h(%rip), %rcx
        movl    $-28, %edx
        .p2align 4,,10
        .p2align 3
.L8:
        movzwl  c(%rip), %eax
        movl    $0, c(%rip)
        testl   %edx, %edx
        jne     .L2
        .p2align 4,,10
        .p2align 3
.L3:
        cmpw    $2, %ax
        jne     .L3
        movl    $2, c(%rip)
        movq    (%rcx), %rax
        movq    (%rax), %rdx
        cmpl    $4, (%rdx)
        jg      .L5
        movq    d(%rip), %rdx
        movq    %rdx, (%rax)
.L5:
        movl    a(%rip), %eax
        leal    1(%rax), %edx
        movl    %edx, a(%rip)
        cmpl    $2, %edx
        jne     .L8
.L13:
        xorl    %eax, %eax
        ret
.L2:
        movq    (%rcx), %rax
        movq    (%rax), %rdx
        cmpl    $4, (%rdx)
        jg      .L5
        movq    d(%rip), %rdx
        movq    %rdx, (%rax)
        jmp     .L13

Bisects to r12-4790-g4b3a325f07a

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

end of thread, other threads:[~2024-06-20  9:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 17:11 [Bug tree-optimization/110327] New: [12/13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r12-4790-g4b3a325f07a theodort at inf dot ethz.ch
2023-06-21  8:33 ` [Bug tree-optimization/110327] " rguenth at gcc dot gnu.org
2023-06-24  8:09 ` pinskia at gcc dot gnu.org
2023-11-24  3:55 ` pinskia at gcc dot gnu.org
2024-03-08 15:31 ` law at gcc dot gnu.org
2024-03-09  7:32 ` law at gcc dot gnu.org
2024-06-20  9:13 ` [Bug tree-optimization/110327] [12/13/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).