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/111799] New: [14 Regression] Missed Dead Code Elimination since  r14-2365-g2e406f0753e
Date: Fri, 13 Oct 2023 15:46:14 +0000	[thread overview]
Message-ID: <bug-111799-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111799
           Summary: [14 Regression] Missed Dead Code Elimination since
                    r14-2365-g2e406f0753e
           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/bqcvMcbqn

Given the following code:

void foo(void);
static struct d {
    short e;
} g = {205}, *h = &g;
static int i;
static int *j, *a = &i;
static int **k = &j;
static int ****l;
static int *****m;
static char(n)(char b, char c) { return b + c; }
static char(o)(char b, char c) { return b * c; }
static short(p)(short f) {
    if (!(((f) >= 1) && ((f) <= 65459))) {
        __builtin_unreachable();
    }
    return 0;
}
static int *q(short);
static void s(struct d) { *k = q(i); }
static int *q(short ad) {
    int b = *a;
    ad = -21;
    for (; ad; ad = n(ad, 7)) p((ad ^ b && *a) <= *a);
    return *k;
}
int main() {
    i = 0;
    for (;; i = 1) {
        q(3);
        char r = o(126 | 1, g.e);
        p(r);
        s(*h);
        if (i) break;
        m = &l;
    }
    if (m)
        ;
    else
        foo();
    ;
}

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

main:
        movl    $2, %esi
        xorl    %ecx, %ecx
        xorl    %r9d, %r9d
        movl    $8, %edi
        movl    $0, i(%rip)
        .p2align 4,,10
        .p2align 3
.L10:
        movl    $-21, %eax
.L2:
        testl   %ecx, %ecx
        je      .L29
        leal    7(%rax), %edx
        movsbw  %dl, %r8w
        testb   %dl, %dl
        je      .L23
.L5:
        movl    $8, %eax
        cmpb    $1, %dl
        je      .L2
        movl    %r8d, %eax
        leal    7(%rax), %edx
        movsbw  %dl, %r8w
        testb   %dl, %dl
        jne     .L5
        .p2align 4,,10
        .p2align 3
.L23:
        movl    $-21, %eax
        addb    $7, %al
        je      .L30
.L9:
        movsbl  %al, %edx
        cmpl    %edx, %ecx
        cmove   %edi, %eax
        cbtw
        addb    $7, %al
        jne     .L9
.L30:
        cmpl    $1, %esi
        je      .L31
        movl    $1, %esi
        movl    $1, %ecx
        movl    $1, %r9d
        jmp     .L10
        .p2align 4,,10
        .p2align 3
.L29:
        testb   $1, %al
        je      .L4
        leal    7(%rax), %edx
        movsbw  %dl, %ax
        testb   %dl, %dl
        je      .L23
.L4:
        leal    14(%rax), %edx
        movsbw  %dl, %ax
        testb   %dl, %dl
        jne     .L4
        jmp     .L23
        .p2align 4,,10
        .p2align 3
.L31:
        testb   %r9b, %r9b
        je      .L11
        movq    $l, m(%rip)
        movl    %ecx, i(%rip)
.L25:
        xorl    %eax, %eax
        ret
.L11:
        cmpq    $0, m(%rip)
        jne     .L25
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        popq    %rdx
        ret

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        movq    $l, m(%rip)
        xorl    %eax, %eax
        movl    $1, i(%rip)
        ret

Bisects to r14-2365-g2e406f0753e

             reply	other threads:[~2023-10-13 15:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-13 15:46 theodort at inf dot ethz.ch [this message]
2023-10-13 15:48 ` [Bug tree-optimization/111799] " pinskia at gcc dot gnu.org
2023-10-13 15:50 ` pinskia at gcc dot gnu.org
2023-10-13 15:52 ` pinskia at gcc dot gnu.org
2023-10-16  4:08 ` pinskia at gcc dot gnu.org
2023-10-17 11:08 ` theodort at inf dot ethz.ch
2023-10-18 23:55 ` [Bug middle-end/111799] " pinskia at gcc dot gnu.org
2024-03-07 21:04 ` law at gcc dot gnu.org
2024-03-09  5:43 ` law at gcc dot gnu.org
2024-05-07  7:42 ` [Bug middle-end/111799] [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-111799-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).