From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 29B2D3858D28; Wed, 15 Dec 2021 02:54:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29B2D3858D28 From: "lingling.kong7 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103723] New: Loop invariant motion pass failed to remove unused code from loop Date: Wed, 15 Dec 2021 02:54:40 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: lingling.kong7 at gmail dot com 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: Wed, 15 Dec 2021 02:54:40 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103723 Bug ID: 103723 Summary: Loop invariant motion pass failed to remove unused code from loop Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: lingling.kong7 at gmail dot com Target Milestone: --- https://godbolt.org/z/b7x1s5Yrn For this case, the instruction `mov ecx, eax` in bb `.L3` could remove from loop body and could sink to '.L8' and '.L1'. After ivopt pass the tree dump is: uint32_t test (uint32_t buf_avail,=20 const uint8_t * buf, const uint8_t * buf_back) { sizetype ivtmp.7; uint32_t len_test; unsigned char _3; sizetype _4; unsigned char _6; sizetype _7; unsigned int _15; unsigned int _16; unsigned int _17; [local count: 114863530]: if (buf_avail_8(D) > 2) goto ; [94.50%] else goto ; [5.50%] [local count: 6317494]: goto ; [100.00%] [local count: 108546036]:=20 _15 =3D buf_avail_8(D) + 4294967293; _7 =3D (sizetype) _15; _4 =3D _7 + 3; goto ; [100.00%] [local count: 958878296]: _16 =3D (unsigned int) ivtmp.7_19; len_test_12 =3D _16 + 1; ivtmp.7_18 =3D ivtmp.7_19 + 1; if (ivtmp.7_18 !=3D _4) goto ; [94.50%] else goto ; [5.50%] [local count: 52738306]: # len_test_21 =3D PHI goto ; [100.00%] [local count: 906139990]: [local count: 1014686026]: # ivtmp.7_19 =3D PHI _17 =3D (unsigned int) ivtmp.7_19; len_test_13 =3D _17; _3 =3D MEM[(const uint8_t *)buf_9(D) + ivtmp.7_19 * 1]; _6 =3D MEM[(const uint8_t *)buf_back_11(D) + ivtmp.7_19 * 1]; if (_3 =3D=3D _6) goto ; [94.50%] else goto ; [5.50%] [local count: 55807731]: # len_test_20 =3D PHI [local count: 114863531]: # len_test_14 =3D PHI return len_test_14; } len_test_13 is unused in loop body and could sink to bb 5.=