From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4231A3858C74; Tue, 15 Feb 2022 11:26:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4231A3858C74 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104543] [12 Regression] wrong code at -O3 on x86_64-linux-gnu Date: Tue, 15 Feb 2022 11:26:34 +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: 12.0 X-Bugzilla-Keywords: needs-bisection, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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, 15 Feb 2022 11:26:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104543 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |matz at gcc dot gnu.org --- Comment #5 from Richard Biener --- Hmm, no. The issue seems to be that the outer loop is head-controlled which means unrolling duplicates the exit check in the middle of the fused loop. I think we miss a check for an empty header of the outer loop, the perfect nest check is too simplistic here. We have b =3D 0; do { if (b > 2) break; c =3D 0; do { a[c] ^=3D 1; ++c } while (c <=3D 2); ++b; } while (1); and fusing ends up with something like b =3D 0; do { c =3D 0; do { a[c] ^=3D 1; if (b > 2) break; a[c] ^=3D 1; } while (c <=3D 2); b+=3D2; } while (1); in particular the comment in bb_prevents_fusion_p saying /* BB is duplicated by outer unrolling and then all N-1 first copies move into the body of the fused inner loop. If BB exits the outer loop the last copy still does so, and the first N-1 copies are cancelled by loop unrolling, so also after fusion it's the exit block. looks wrong. Yes, the first is cancelled but the remaining is not the exit block.=