public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "shaohua.li at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3)
Date: Mon, 16 May 2022 13:15:58 +0000	[thread overview]
Message-ID: <bug-105618-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 105618
           Summary: Missed loop body simplification by -O3 (trunk v.s.
                    10.3)
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following code, gcc truck -O3 fails to optimize away the loop body,
while gcc10.3 can. You can see from the assembly code that gcc10.3 figured out
that the variable c would be a constant after the loop while gcc-trunk didn't.

$cat a.c
static int b=4;
int c;
int main() {
  int e[5] = {1,1,1,1,1};
  for (; b >= 0; b--) {
    c = e[b];
  }
  return 0;
}
$
$gcc-trunk -O3 -S -o trunk.s a.c
$gcc-10-3  -O3 -S -o 10-3.s a.c
$wc trunk.s 10-3.s
  66  147 1005 trunk.s
  52  106  698 10-3.s
 118  253 1703 total
$
$cat 10-3.s
main:
.LFB0:
        .cfi_startproc
        endbr64
        movl    b(%rip), %eax
        testl   %eax, %eax
        js      .L2
        movl    $1, c(%rip)
        movl    $-1, b(%rip)
.L2:
        xorl    %eax, %eax
        ret
$
$cat trunk.s
main:
.LFB0:
        .cfi_startproc
        movdqa  .LC0(%rip), %xmm0
        movl    b(%rip), %eax
        movl    $1, -24(%rsp)
        movaps  %xmm0, -40(%rsp)
        testl   %eax, %eax
        js      .L2
        movslq  %eax, %rdx
        leal    -1(%rax), %ecx
        movl    -40(%rsp,%rdx,4), %edx
        je      .L3
        leal    -2(%rax), %edx
        cmpl    $1, %eax
        je      .L10
        leal    -3(%rax), %ecx
        cmpl    $2, %eax
        je      .L6
        leal    -4(%rax), %edx
        cmpl    $3, %eax
        je      .L10
.L6:
        movslq  %edx, %rdx
        movl    -40(%rsp,%rdx,4), %edx
.L3:
        movl    %edx, c(%rip)
        movl    $-1, b(%rip)
.L2:
        xorl    %eax, %eax
        ret
.L10:
        movslq  %ecx, %rcx
        movl    -40(%rsp,%rcx,4), %edx
        jmp     .L3
$

             reply	other threads:[~2022-05-16 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 13:15 shaohua.li at inf dot ethz.ch [this message]
2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
2022-05-17  6:57 ` [Bug tree-optimization/105618] [11/12/13 Regression] " rguenth at gcc dot gnu.org
2022-05-17  7:32 ` rguenth at gcc dot gnu.org
2022-05-17  7:48 ` rguenth at gcc dot gnu.org
2022-05-17  8:46 ` cvs-commit at gcc dot gnu.org
2022-05-17  8:46 ` [Bug tree-optimization/105618] [11/12 " rguenth at gcc dot gnu.org
2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
2022-07-22 11:21 ` [Bug tree-optimization/105618] [11 " cvs-commit at gcc dot gnu.org
2022-07-22 11:22 ` 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-105618-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).