From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9D73E3858C1F; Tue, 15 Feb 2022 14:47:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D73E3858C1F From: "matz at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104543] [9/10/11 Regression] wrong code at -O3 on x86_64-linux-gnu Date: Tue, 15 Feb 2022 14:47:20 +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: matz at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 9.5 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, 15 Feb 2022 14:47:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104543 --- Comment #11 from Michael Matz --- (In reply to Richard Biener from comment #5) > in particular the comment in bb_prevents_fusion_p saying >=20 > /* 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 l= oop > 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. >=20 > looks wrong. Yes, the first is cancelled but the remaining is not the > exit block. I think your patch is fine and fixes the bug. We can possibly do better al= so for head-controlled loops by just reversing the above: the _first_ of the N exit-bb copies needs to remain (and stay in front of the inner loop), and the last N-1 copies need to be cancelled. Needs to be carefully thought through, but something like that should be possible.=