From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F33933846463; Tue, 27 Jul 2021 07:03:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F33933846463 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/37810] Bad store sinking job Date: Tue, 27 Jul 2021 07:03:38 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.4.0 X-Bugzilla-Keywords: alias, missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW 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: Message-ID: In-Reply-To: References: 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: Tue, 27 Jul 2021 07:03:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D37810 --- Comment #7 from Richard Biener --- (In reply to Richard Biener from comment #2) > The original testcase (from an IRC discussion) reduced to a C testcase is: >=20 > struct A { > int n; > int m; > }; >=20 > void g(); >=20 > void test (struct A* iter) > { > struct A end =3D { 0, 0 }; > while (iter->n !=3D end.n) > { > iter->n =3D iter->n + 1; > if (iter->n =3D=3D iter->m) > g(); > } > } >=20 > where there is an optimization possibility to sink the store to iter->n to > before the call and apply load-store motion to iter->n for the remaining > loop. So to clarify the desired code would look like void test (struct A* iter) { struct A end =3D { 0, 0 }; int tem =3D iter->n; while (tem !=3D end.n) { tem =3D tem + 1; if (tem =3D=3D iter->m) { iter->n =3D tem; g(); tem =3D iter->n; } } iter->n =3D tem; } PRE does half of the job, but then sinking would need to duplicate the store on the loop exit, something it currently cannot do (the logic is to duplica= te to two places less frequently executed).=