public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3)
@ 2022-05-16 13:15 shaohua.li at inf dot ethz.ch
  2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-05-16 13:15 UTC (permalink / raw)
  To: gcc-bugs

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
$

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-07-22 11:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
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

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).