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/110414] New: [14 Regression] Dead Code Elimination Regression  since  r14-1127-g9e2017ae6ac
Date: Mon, 26 Jun 2023 15:06:40 +0000	[thread overview]
Message-ID: <bug-110414-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 110414
           Summary: [14 Regression] Dead Code Elimination Regression
                    since  r14-1127-g9e2017ae6ac
           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/5E795dPvY

Given the following code:

void foo(void);
static int a, b, e, l, m, n;
static int *c = &a, *j;
static int **d = &c;
static int ***f;
void __assert_fail(char *, char *, int, char *) __attribute__((__noreturn__));
static void g(char) {
    if (c == &b || c == &a)
        ;
    else
        __assert_fail("", "", 3, __PRETTY_FUNCTION__);
}
static void h();
static int *i();
static short k() {
    j = i();
    h();
    **f = &e;
    if (c == &b || c == &a || c == 0)
        __assert_fail("", "", 6, __PRETTY_FUNCTION__);
    return 0;
}
static void h() {
    if (l) {
        for (; l; l = l - 8) *d = &m;
        if (c == &a)
            ;
        else
            __assert_fail("", "", 9, __PRETTY_FUNCTION__);
    }
    if (c == &b || c == &a || c == 0)
        ;
    else {
        foo();
        __assert_fail("", "", 8, __PRETTY_FUNCTION__);
    }
}
static int *i() {
    if (c == &b || c == &a)
        ;
    else {
        __builtin_unreachable();
        __assert_fail("", "", 6, __PRETTY_FUNCTION__);
    }
    return &n;
}
int main() { g(a && k()); }

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

main:
        pushq   %rcx
        cmpl    $0, a(%rip)
        je      .L2
        movl    l(%rip), %edx
        testl   %edx, %edx
        je      .L3
        movl    %edx, %eax
        movl    $__PRETTY_FUNCTION__.1, %ecx
        movq    $m, c(%rip)
        shrl    $3, %eax
        imull   $-8, %eax, %eax
        addl    %edx, %eax
        movl    $9, %edx
        movl    %eax, l(%rip)
        jmp     .L7
.L3:
        movq    c(%rip), %rax
        cmpq    $a, %rax
        sete    %dl
        cmpq    $b, %rax
        sete    %cl
        orb     %cl, %dl
        jne     .L4
        testq   %rax, %rax
        je      .L4
        call    foo
        movl    $__PRETTY_FUNCTION__.1, %ecx
        movl    $8, %edx
.L7:
        movl    $.LC0, %esi
        movq    %rsi, %rdi
        call    __assert_fail
.L4:
        movl    $__PRETTY_FUNCTION__.2, %ecx
        movl    $6, %edx
        jmp     .L7
.L2:
        movq    c(%rip), %rax
        cmpq    $a, %rax
        je      .L5
        cmpq    $b, %rax
        je      .L5
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $3, %edx
        jmp     .L7
.L5:
        xorl    %eax, %eax
        popq    %rdx
        ret

gcc-13.1.0 -Os eliminates the call to foo:

main:
        pushq   %rcx
        movq    c(%rip), %rdx
        cmpq    $a, %rdx
        sete    %al
        cmpq    $b, %rdx
        sete    %dl
        orl     %edx, %eax
        cmpl    $0, a(%rip)
        je      .L2
        movl    l(%rip), %edx
        testl   %edx, %edx
        je      .L3
        movl    %edx, %eax
        movl    $__PRETTY_FUNCTION__.1, %ecx
        movq    $m, c(%rip)
        shrl    $3, %eax
        imull   $-8, %eax, %eax
        addl    %edx, %eax
        movl    $9, %edx
        movl    %eax, l(%rip)
        jmp     .L7
.L2:
        testb   %al, %al
        jne     .L5
        movl    $__PRETTY_FUNCTION__.0, %ecx
        movl    $3, %edx
.L7:
        movl    $.LC0, %esi
        movq    %rsi, %rdi
        call    __assert_fail
.L3:
        movl    $__PRETTY_FUNCTION__.2, %ecx
        movl    $6, %edx
        jmp     .L7
.L5:
        xorl    %eax, %eax
        popq    %rdx
        ret

Bisects to r14-1127-g9e2017ae6ac

             reply	other threads:[~2023-06-26 15:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26 15:06 theodort at inf dot ethz.ch [this message]
2023-06-27  6:33 ` [Bug tree-optimization/110414] " rguenth at gcc dot gnu.org
2023-06-27  9:37 ` rguenth at gcc dot gnu.org
2024-03-08 15:30 ` law at gcc dot gnu.org
2024-05-07  7:40 ` [Bug tree-optimization/110414] [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-110414-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).