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/111864] New: [14 Regression] Dead Code Elimination Regression since r14-4038-gb975c0dc3be
Date: Wed, 18 Oct 2023 14:10:10 +0000	[thread overview]
Message-ID: <bug-111864-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111864
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-4038-gb975c0dc3be
           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/PoYvWMG7T

Given the following code:

void foo(void);
static int d, g = 4, k;
static int *h, *j, *s;
static int **i = &h, **t = &s;
static int ***l = &i;
static unsigned short *m, *n;
static unsigned short **o = &n, **u = &m;
void __assert_fail() __attribute__((__noreturn__));
static short(a)(short b, int c) { return b << c; }
static int(e)(int f) {
    if (!(((f) >= 0) && ((f) <= 0))) {
        __builtin_unreachable();
    }
    return d;
}
static int ***p(int **q) {
    j = *q;
    return &i;
}
static int *r() {
    short v = a((g && p(t)) <= 0, 5);
    e(v);
    if (s) o = u;
    if (o == &m || o == &n)
        ;
    else
        __assert_fail();
    return &k;
}
int main() {
    **l = r();
    if (h)
        ;
    else
        __assert_fail();
    if (j == &g == 0)
        ;
    else
        __assert_fail();
    if (o == &m || o == &n)
        ;
    else
        foo();
    ;
}

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

main:
        subq    $8, %rsp
        movq    s(%rip), %rax
        movq    i(%rip), %rdx
        movq    %rax, j(%rip)
        testq   %rax, %rax
        je      .L17
        movq    $k, (%rdx)
        cmpq    $0, h(%rip)
        movq    $m, o(%rip)
        je      .L5
        cmpq    $g, %rax
        je      .L5
        movl    $m, %eax
.L10:
        cmpq    $n, %rax
        je      .L12
        cmpq    $m, %rax
        je      .L12
        call    foo
.L12:
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L17:
        movq    o(%rip), %rax
        cmpq    $m, %rax
        je      .L18
        cmpq    $n, %rax
        jne     .L5
        movq    $k, (%rdx)
        cmpq    $0, h(%rip)
        jne     .L10
.L5:
        xorl    %eax, %eax
        call    __assert_fail
.L18:
        movq    $k, (%rdx)
        cmpq    $0, h(%rip)
        jne     .L12
        jmp     .L5

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        movq    s(%rip), %rax
        movq    i(%rip), %rdx
        movq    %rax, j(%rip)
        testq   %rax, %rax
        je      .L2
        movq    $k, (%rdx)
        cmpq    $0, h(%rip)
        movq    $m, o(%rip)
        je      .L4
        cmpq    $g, %rax
        je      .L4
.L8:
        xorl    %eax, %eax
        ret
.L2:
        movq    o(%rip), %rax
        cmpq    $m, %rax
        je      .L5
        cmpq    $n, %rax
        jne     .L4
.L5:
        movq    $k, (%rdx)
        cmpq    $0, h(%rip)
        jne     .L8
.L4:
        pushq   %rax
        xorl    %eax, %eax
        call    __assert_fail

Bisects to r14-4038-gb975c0dc3be

             reply	other threads:[~2023-10-18 14:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 14:10 theodort at inf dot ethz.ch [this message]
2023-10-18 15:09 ` [Bug tree-optimization/111864] " pinskia at gcc dot gnu.org
2023-10-18 16:15 ` [Bug tree-optimization/111864] [12/13/14 Regression] Dead Code Elimination Regression pinskia at gcc dot gnu.org
2024-03-07 21:04 ` law at gcc dot gnu.org
2024-03-09  5:31 ` law at gcc dot gnu.org
2024-03-15 13:25 ` aldyh 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-111864-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).