From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EB6903858CDA; Tue, 5 Mar 2024 11:54:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB6903858CDA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709639675; bh=4HdSmMIdiKlw+TAcv5YzTGyvpDVONGjiu5lwmAX7j3s=; h=From:To:Subject:Date:From; b=iQoh34dqLTR247Bp+ocWm8/ckO94u1ydnFBCjqPIh/pW0XhUb1m7wIJiffLRZlnhU mSjQQ5KLBkGFtz5nIiNthK0pgN7B73PZGV+D9JUjgz6q/t9POhdR3RINf6hXIRz40h DgLjktZFSF4AhRKI512kRC4hHFyRBrYxA2zRVubo= From: "absoler at smail dot nju.edu.cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114236] New: introduce unnecessary store operation when unrolling a loop Date: Tue, 05 Mar 2024 11:54:35 +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.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: absoler at smail dot nju.edu.cn 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114236 Bug ID: 114236 Summary: introduce unnecessary store operation when unrolling a loop Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: absoler at smail dot nju.edu.cn Target Milestone: --- here's the code, compiled with gcc-13.2.0 -O2 ``` // https://godbolt.org/z/5xWrr44hn short g_16[2][1] =3D {{(-8L)},{(-8L)}}; int g_22 =3D (-1L); int g_71 =3D 0xA62A9801L; int *g_70 =3D &g_71; int c; void func_1() { int d; for (; c;) ; for (d =3D -1; d < 17; d++) { short *e =3D g_16[0]; *g_70 =3D *e =3D g_22; } } ``` ``` func_1(): 401440: mov 0x10762(%rip),%eax # 411ba8 401446: test %eax,%eax 401448: je 401450 40144a: jmp 40144a 40144c: nopl 0x0(%rax) 401450: mov 0x2c09(%rip),%rsi # 404060 401457: mov $0x12,%eax 40145c: nopl 0x0(%rax) 401460: mov 0x2c06(%rip),%ecx # 40406c 401466: movswl %cx,%edx 401469: mov %edx,(%rsi) 40146b: sub $0x1,%eax 40146e: jne 401460 401470: mov %cx,0x2bf9(%rip) # 404070 401477: mov %edx,(%rsi) ``` we can see that the store operation at 0x401477 is unnecessary and lead to = 19 times memory write, more one time than the loop. And I found this behavior showing up from the `141t.lim2` file when I check= the output files of `-fdump-tree-all`.=