From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 66BE93856DD5; Mon, 16 May 2022 13:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66BE93856DD5 From: "shaohua.li at inf dot ethz.ch" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shaohua.li at inf dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 May 2022 13:15:58 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105618 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=3D4; int c; int main() { int e[5] =3D {1,1,1,1,1}; for (; b >=3D 0; b--) { c =3D 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 $=