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/111293] New: [14 Regression] Missed Dead Code Elimination since r14-3414-g0cfc9c953d0
Date: Tue, 05 Sep 2023 15:01:10 +0000	[thread overview]
Message-ID: <bug-111293-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 111293
           Summary: [14 Regression] Missed Dead Code Elimination since
                    r14-3414-g0cfc9c953d0
           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/9aj7sr5d6

Given the following code:

void foo(void);
static int a, d;
static short e;
static int(f)(int b, int c) { return c == 0 ? b : b / c; }
static char g(char h) {
    char i = 1;
    int j = 8;
    e = 3;
    for (; d; ++d) {
        if (f(0 == j, e)) return a;
        for (; i; i--) {
            if (j) {
                if (e)
                    ;
                else if (a)
                    continue;
                else
                    foo();
                j = -h;
                break;
            }
            __builtin_unreachable();
            break;
        }
    }
    return 1;
}
int main() {
    g(-1);
    a = e;
}

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

main:
        subq    $8, %rsp
        movl    d(%rip), %ecx
        movl    $3, %edx
        movw    %dx, e(%rip)
        testl   %ecx, %ecx
        je      .L6
        movl    $3, %edx
        .p2align 4,,10
        .p2align 3
.L2:
        testw   %dx, %dx
        jne     .L3
        movl    a(%rip), %eax
        testl   %eax, %eax
        je      .L18
.L5:
        addl    $1, d(%rip)
        jne     .L5
.L6:
        movswl  e(%rip), %eax
        movl    %eax, a(%rip)
        xorl    %eax, %eax
        addq    $8, %rsp
        ret
        .p2align 4,,10
        .p2align 3
.L18:
        call    foo
.L3:
        addl    $1, d(%rip)
        movzwl  e(%rip), %edx
        jne     .L2
        jmp     .L6

gcc-13.2.0 -O2 eliminates the call to foo:

main:
        movl    d(%rip), %edx
        movl    $3, %eax
        movw    %ax, e(%rip)
        testl   %edx, %edx
        je      .L3
        movl    $0, d(%rip)
.L3:
        movl    $3, a(%rip)
        xorl    %eax, %eax
        ret

Bisects to r14-3414-g0cfc9c953d0

             reply	other threads:[~2023-09-05 15:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 15:01 theodort at inf dot ethz.ch [this message]
2023-09-05 17:25 ` [Bug tree-optimization/111293] " pinskia at gcc dot gnu.org
2023-09-05 17:40 ` pinskia at gcc dot gnu.org
2023-09-05 17:40 ` pinskia at gcc dot gnu.org
2023-11-24 15:56 ` amacleod at redhat dot com
2024-03-07 23:21 ` law at gcc dot gnu.org
2024-04-09  9:38 ` mikael at gcc dot gnu.org
2024-04-09  9:47 ` mikael at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/111293] [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-111293-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).