public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "theodort at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/111292] New: Missed Dead Code Elimination since r14-2228-g02460c0b8c9
Date: Tue, 05 Sep 2023 14:56:54 +0000	[thread overview]
Message-ID: <bug-111292-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111292
           Summary: Missed Dead Code Elimination since
                    r14-2228-g02460c0b8c9
           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/sxj43ojn3

Given the following code:

void foo(void);
static struct {
    int a;
    char b;
} c;
static int d, f, g;
static int *e = &d, *h, *i;
static int **j = &h;
int main() {
    {
        short k = d;
        int l;
        for (; c.a; c.a--) {
            int **m = 0;
            int *n = &l;
            if (*e)
                g = *i != 0;
            else
                __builtin_unreachable();
            f = 8;
            for (; f; f--) {
                *n = c.b || k;
                if ((k && *i) + g) {
                    int ***o = &m;
                    *o = j;
                } else
                    i = &g;
            }
            if (m == 0 || m == &h)
                ;
            else
                foo();
            ;
        }
    }
}

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

main:
        movl    c(%rip), %eax
        pushq   %rbx
        movzwl  d(%rip), %ebx
        testl   %eax, %eax
        je      .L37
        .p2align 4,,10
        .p2align 3
.L2:
        movq    i(%rip), %rcx
        xorl    %esi, %esi
        movl    (%rcx), %edx
        testl   %edx, %edx
        setne   %sil
        cmpb    $0, c+4(%rip)
        movl    %esi, g(%rip)
        jne     .L3
        testw   %bx, %bx
        jne     .L4
        testl   %edx, %edx
        jne     .L5
        movl    $0, f(%rip)
        movq    $g, i(%rip)
.L6:
        subl    $1, %eax
        movl    %eax, c(%rip)
        jne     .L2
.L37:
        xorl    %eax, %eax
        popq    %rbx
        ret
        .p2align 4,,10
        .p2align 3
.L3:
        testw   %bx, %bx
        je      .L45
        movl    (%rcx), %esi
        movl    %edx, %edi
        orl     %esi, %edi
        je      .L28
        xorl    %edi, %edi
        testl   %esi, %esi
        je      .L46
        .p2align 4,,10
        .p2align 3
.L23:
        movl    $0, f(%rip)
        movl    $h, %esi
        testb   %dil, %dil
        je      .L6
.L24:
        movq    %rcx, i(%rip)
.L11:
        testq   %rsi, %rsi
        je      .L6
        cmpq    $h, %rsi
        je      .L6
        call    foo
        movl    c(%rip), %eax
        subl    $1, %eax
        movl    %eax, c(%rip)
        jne     .L2
        jmp     .L37
        .p2align 4,,10
        .p2align 3
.L4:
        testl   %edx, %edx
        jne     .L5
        movl    $0, f(%rip)
        movl    (%rcx), %esi
        testl   %esi, %esi
        je      .L43
.L8:
        movl    $h, %esi
        jmp     .L11
        .p2align 4,,10
        .p2align 3
.L45:
        movl    $0, f(%rip)
        testl   %edx, %edx
        jne     .L8
.L43:
        movq    $g, i(%rip)
        jmp     .L6
        .p2align 4,,10
        .p2align 3
.L5:
        movl    $0, f(%rip)
        jmp     .L6
.L28:
        movl    $1, %edi
        movl    $g, %ecx
        xorl    %esi, %esi
.L12:
        movl    (%rcx), %r8d
        movl    %edx, %r9d
        orl     %r8d, %r9d
        jne     .L47
        movl    $1, %edi
        movl    $g, %ecx
.L14:
        movl    (%rcx), %r8d
        movl    %edx, %r10d
        orl     %r8d, %r10d
        je      .L31
        movl    $h, %esi
        testl   %r8d, %r8d
        jne     .L23
.L15:
        movl    (%rcx), %r8d
        movl    %edx, %r11d
        orl     %r8d, %r11d
        je      .L32
        movl    $h, %esi
        testl   %r8d, %r8d
        jne     .L23
.L16:
        movl    (%rcx), %r8d
        movl    %edx, %r11d
        orl     %r8d, %r11d
        je      .L33
        movl    $h, %esi
        testl   %r8d, %r8d
        jne     .L23
.L18:
        movl    (%rcx), %r8d
        movl    %edx, %r10d
        orl     %r8d, %r10d
        je      .L48
        testl   %r8d, %r8d
        jne     .L23
        movl    $h, %esi
        testl   %edx, %edx
        jne     .L27
.L21:
        movl    $1, %edi
        movl    $g, %ecx
.L27:
        orl     (%rcx), %edx
        jne     .L23
        xorl    %ecx, %ecx
        movl    %ecx, f(%rip)
        movl    $g, %ecx
        jmp     .L24
.L47:
        movl    $h, %esi
        testl   %r8d, %r8d
        jne     .L23
        jmp     .L14
.L48:
        cmpl    $0, g(%rip)
        je      .L21
        xorl    %edx, %edx
        movl    $g, %ecx
        movl    $h, %esi
        movl    %edx, f(%rip)
        jmp     .L24
.L31:
        movl    $1, %edi
        movl    $g, %ecx
        jmp     .L15
.L32:
        movl    $1, %edi
        movl    $g, %ecx
        jmp     .L16
.L33:
        movl    $1, %edi
        movl    $g, %ecx
        jmp     .L18
.L46:
        movl    $h, %esi
        jmp     .L12

gcc-13.2.0 -O3 eliminates the call to foo:

main:
        movl    c(%rip), %eax
        movzwl  d(%rip), %edi
        testl   %eax, %eax
        je      .L13
        .p2align 4,,10
        .p2align 3
.L2:
        movq    i(%rip), %rdx
        xorl    %ecx, %ecx
        movl    (%rdx), %esi
        testl   %esi, %esi
        setne   %cl
        movl    %ecx, g(%rip)
        jne     .L7
        testw   %di, %di
        je      .L14
        movl    (%rdx), %edx
        testl   %edx, %edx
        je      .L14
.L7:
        movl    $0, f(%rip)
.L6:
        subl    $1, %eax
        movl    %eax, c(%rip)
        jne     .L2
.L13:
        xorl    %eax, %eax
        ret
        .p2align 4,,10
        .p2align 3
.L14:
        movl    $0, f(%rip)
        movq    $g, i(%rip)
        jmp     .L6

Bisects to r14-2228-g02460c0b8c9

             reply	other threads:[~2023-09-05 14:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 14:56 theodort at inf dot ethz.ch [this message]
2023-09-05 21:03 ` [Bug tree-optimization/111292] [14 Regression] " pinskia at gcc dot gnu.org
2023-09-05 21:06 ` pinskia at gcc dot gnu.org
2023-11-24  4:36 ` pinskia at gcc dot gnu.org
2024-03-07 23:21 ` law at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/111292] [14/15 " rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-111292-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).