From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F0FAE3858005; Mon, 29 Nov 2021 15:23:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0FAE3858005 From: "marxin 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: Mon, 29 Nov 2021 15:23:30 +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: marxin at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: marxin 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: Mon, 29 Nov 2021 15:23:31 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103278 --- Comment #11 from Martin Li=C5=A1ka --- (In reply to Richard Biener from comment #9) > So for >=20 > rl78-elf > if-to-switch-5 >=20 > we fail the JT because it's not enabled for the target. Yes. > w/o the CD-DCE > change we build a bit-test from >=20 > ;; Canonical GIMPLE case clusters: 34 39 44 46 58 59 60 62 92 >=20 > which we then expand into a new switch without any bit tests(?). No, the message just tells what's the canonical switch form and the transformation doesn't happen. > After the CD-DCE change we have improved(?) clusters: >=20 > ;; Canonical GIMPLE case clusters: 34 39 44 46 58-60 62 92 Which is nicer! >=20 > and thus the output is no longer(?) beneficial. Yes, because BT counts the number of edges in the costing model and this is definitelly more precise. Does not make sense doing a BT for 10-30 even though it's theoretically 21 edges. >=20 > I wonder if the merging of clusters done as part of the sorting is > counter-productive since it distorts the profitability? If we check agai= nst > the > size of the unmerged clusters like with the following the testcase > will pass again. I also notice we don't take advantage of the > merging and create The costing is not improved by the change. >=20 > switch (c_3(D)) [INV], case 34: [INV], case 39: > [INV], case 44: [INV], case 46: [INV], case 58: > [INV], case 59: [INV], case 60: [INV], case 62: [INV], > case 92: [INV]> >=20 > instead of one 'case 58-60:' >=20 > diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc > index 16fabef7ca0..b64a1915e15 100644 > --- a/gcc/gimple-if-to-switch.cc > +++ b/gcc/gimple-if-to-switch.cc > @@ -240,7 +240,7 @@ if_chain::is_beneficial () >=20=20 > vec output > =3D jump_table_cluster::find_jump_tables (filtered_clusters); > - bool r =3D output.length () < filtered_clusters.length (); > + bool r =3D output.length () < clusters.length (); > if (r) > { > dump_clusters (&output, "JT can be built"); > @@ -251,7 +251,7 @@ if_chain::is_beneficial () > output.release (); >=20=20 > output =3D bit_test_cluster::find_bit_tests (filtered_clusters); > - r =3D output.length () < filtered_clusters.length (); > + r =3D output.length () < clusters.length (); > if (r) > dump_clusters (&output, "BT can be built"); >=20=20 >=20 > Martin, can you please look into this? Sure, I tend to change the test in the following way: gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c index ceeae908821..54771e64e59 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-5.c @@ -4,8 +4,8 @@ int crud (unsigned char c) { return (((((((((((int) c =3D=3D 46) || (int) c =3D=3D 44) - || (int) c =3D=3D 58) || (int) c =3D=3D 59) || (int) c =3D= =3D 60) - || (int) c =3D=3D 62) || (int) c =3D=3D 34) || (int) c =3D=3D= 92) + || (int) c =3D=3D 58) || (int) c =3D=3D 60) || (int) c =3D= =3D 62) + || (int) c =3D=3D 64) || (int) c =3D=3D 34) || (int) c =3D=3D= 92) || (int) c =3D=3D 39) !=3D 0); }=