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/110891] New: [14 Regression] Dead Code Elimination Regression since r14-2674-gd0de3bf9175
Date: Thu, 03 Aug 2023 16:01:08 +0000	[thread overview]
Message-ID: <bug-110891-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110891
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-2674-gd0de3bf9175
           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/njdE3xof4

Given the following code:

void foo(void);
static int a, c = 7, d, o, q;
static int *b = &a, *f, *j = &d, *n = &c, *ae;
static short e, m;
static short *i = &e;
static char r;
void __assert_fail(char *, char *, int, char *) __attribute__((__noreturn__));
static const short g();
static void h();
static int *k(int) {
    (*i)++;
    *j ^= *b;
    return &a;
}
static void l(unsigned p) {
    int *aa = &o;
    h();
    o = 5 ^ g() && p;
    if (f == &d || f == &c || f == &a)
        ;
    else {
        foo();
        __assert_fail("", "", 3, __PRETTY_FUNCTION__);
    }
    *aa ^= *n;
    if (*aa)
        if (!(((p) >= 0) && ((p) <= 0))) {
            __builtin_unreachable();
        }
    k(p);
}
static const short g() { return q; }
static void h() {
    unsigned ag = c;
    d = ag > r ? ag : 0;
    ae = k(c);
    f = ae;
    if (ae == &d || ae == &c || ae == &a)
        ;
    else
        __assert_fail("", "", 4, __PRETTY_FUNCTION__);
}
int main() {
    l(a);
    m || (*b |= 64);
    *b &= 5;
}

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

main:
        subq    $8, %rsp
        movl    c(%rip), %eax
        movl    %eax, d(%rip)
        call    k.isra.0
        cmpq    $c, %rax
        movq    %rax, f(%rip)
        sete    %cl
        cmpq    $a, %rax
        sete    %dil
        cmpq    $d, %rax
        sete    %dl
        orb     %cl, %dl
        jne     .L4
        testb   %dil, %dil
        je      .L15
.L4:
        cmpq    $d, %rax
        je      .L6
        testb   %cl, %cl
        jne     .L6
        testb   %dil, %dil
        je      .L16
.L6:
        call    k.isra.0
        andl    $5, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L16:
        call    foo
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.1, %ecx
        movl    $3, %edx
        movq    %rsi, %rdi
        call    __assert_fail
.L15:
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $4, %edx
        movq    %rsi, %rdi
        call    __assert_fail

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        subq    $8, %rsp
        movl    c(%rip), %eax
        movl    %eax, d(%rip)
        call    k.isra.0
        cmpq    $c, %rax
        movq    %rax, f(%rip)
        sete    %dl
        cmpq    $d, %rax
        sete    %cl
        orb     %cl, %dl
        jne     .L4
        cmpq    $a, %rax
        jne     .L6
.L4:
        call    k.isra.0
        andl    $5, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
.L6:
        movl    $.LC0, %esi
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $4, %edx
        movq    %rsi, %rdi
        call    __assert_fail

Bisects to r14-2674-gd0de3bf9175

             reply	other threads:[~2023-08-03 16:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 16:01 theodort at inf dot ethz.ch [this message]
2023-08-03 16:03 ` [Bug tree-optimization/110891] " pinskia at gcc dot gnu.org
2023-08-03 16:13 ` pinskia at gcc dot gnu.org
2023-08-04  7:59 ` rguenth at gcc dot gnu.org
2023-08-26  0:00 ` pinskia at gcc dot gnu.org
2023-08-26  0:06 ` pinskia at gcc dot gnu.org
2023-08-26  6:35 ` pinskia at gcc dot gnu.org
2023-08-26  6:35 ` pinskia at gcc dot gnu.org
2023-08-27 23:46 ` pinskia at gcc dot gnu.org
2023-08-28  6:53 ` rguenther at suse dot de
2024-03-07 23:26 ` law at gcc dot gnu.org
2024-03-09  7:01 ` law at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/110891] [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-110891-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).