From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 785F63858C27; Wed, 17 Nov 2021 09:49:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 785F63858C27 From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102981] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) Date: Wed, 17 Nov 2021 09:49:57 +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: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.0 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: Wed, 17 Nov 2021 09:49:57 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102981 --- Comment #6 from Aldy Hernandez --- This looks like a class of problems we could easily get if we wanted. The pattern is: PREHEADER | | V HEADER --> LOOPEXIT | | V SUCC | \ | \ DEAD \ | / | / | v XXXXXX On the PREHEADER->HEADER->SUCC path we want to know if the edge out of SUCC= can be statically determined. The threader can't do this for a number of reaso= ns.=20 First, we'd be essentially peeling an iteration. Second, IIUC, we'd be rotating the loop. However, there's no reason we can't catch this in a loop optimizer like we = did with the loopch pass. This is the exact type of problem that is trivially handled by the path solver, which is quite cheap when you don't have to do = full path discovery like the threader has to do. Something like: gimple *control =3D gimple_outgoing_range_stmt_p (succ); if (control) { auto_vec bbs (3); bbs.quick_push (preheader); bbs.quick_push (header); bbs.quick_push (succ); int_range<2> r; path_range_query query; query.compute_ranges (bbs); query.range_of_stmt (r, control); if (r =3D=3D desired_static_value...) peel(); ... } If "dead code on the first iteration" is something we want to handle, I cou= ld help with the ranger bits if someone gives me a hand with the loop bits.=