From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AE8953857C40; Thu, 18 Nov 2021 08:48:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AE8953857C40 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/103278] [12 Regression] Recent change to cddce inhibits switch optimization Date: Thu, 18 Nov 2021 08:48:04 +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: 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: Thu, 18 Nov 2021 08:48:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103278 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |marxin at gcc dot gnu.org --- Comment #5 from Richard Biener --- So the main issue is that while CD-DCE tries to undo the factorization by running cleanup CFG, this process has the choice between two forwarder bloc= ks to remove - one pre-existing to disambiguate the two edges from the last te= st into the PHI and the one we created. But CFG cleanup simply picks the first candidate which, in some cases is not the newly created one. That results in differe= nt handling of if-to-switch cluster processing. In particular the ->m_has_forward_bb handling seems important. If we do diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc index 16fabef7ca0..157c5f6f10b 100644 --- a/gcc/gimple-if-to-switch.cc +++ b/gcc/gimple-if-to-switch.cc @@ -219,8 +219,7 @@ if_chain::is_beneficial () { simple_cluster *right =3D static_cast (clusters[i]= ); tree type =3D TREE_TYPE (left->get_low ()); - if (!left->m_has_forward_bb - && !right->m_has_forward_bb + if (left->m_has_forward_bb =3D=3D right->m_has_forward_bb && left->m_case_bb =3D=3D right->m_case_bb) { if (wi::eq_p (wi::to_wide (right->get_low ()) - wi::to_wide which seems more natural then even with the original IL we don't get any if-to-switch as we seem to fail JT building because the number of clusters is then just 4 which is lower than case_values_threshold () which is 5. If we supply --param case-values-threshold=3D4 to the testcase it is optimi= zed (that overrides the target default) with the result switch (aChar_10(D)) [INV], case 9 ... 10: [INV], case 12: [INV], case 13: [INV], case 32: [INV], case 48: [IN= V]> : : : # iftmp.0_9 =3D PHI <1(3), 0(2)> : return iftmp.0_9; compared to the following before the CD-DCE change which looks clearly worse (but even the above has unmerged case 12 and 13?!) switch (aChar_10(D)) [INV], case 9 ... 10: [INV], ca= se 12: [INV], case 13: [INV], case 32: [INV], case 48: [IN= V]> : : goto ; [100.00%] : : goto ; [100.00%] : : : # iftmp.0_9 =3D PHI <1(4), 0(2), 1(3), 1(5)> : return iftmp.0_9; so this looks like a testcase issue to me.=