From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21471 invoked by alias); 1 Sep 2017 08:26:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 19683 invoked by uid 89); 1 Sep 2017 08:26:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Sep 2017 08:26:33 +0000 Received: by mail-wm0-f42.google.com with SMTP id v2so3962472wmf.0 for ; Fri, 01 Sep 2017 01:26:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=e/EVj9zxVGacO6dkxEeCNez6XSiv3wXJymm1eXlbfxA=; b=PXr3M+OLzPd+xBR9T8tKmiQE18j/k5X1UOSrNfLqoF5JAwYPgIPE/EbzXjr/6MVpsb +l+WzL8N6MJNgytHfA/aOmqGCSJYF/pmmICpuWxHpQ29UiG+vWyHzbsW2mmGhp6Wf6en vHt8r/HVTVoVgqR1NQEA0jX1FAzcaQ3G/Fl4SBMuW3TrHkmSy+WejlGsAc+B4Um0XDEy W7K6nuYXsk/B77dmx08zgvpZb4ZOH+MOethbz/FWgytA8dYvL6sWqxCcLZ9TxAEZEGh5 kwoefBHC79b6fBp+dOuRX5UTfmXx5gZdVbHYug1MHtCTja5RU+8AZ4jVisgveCafkbFL wTWA== X-Gm-Message-State: AHPjjUj3dfAYvFa+0cF4Ji7YeGfvtujtZC1T0JTwMwDPn6LadQ2PK5YD qE3BgJp3U1YOqdJCvN4yN/stJdQwbg== X-Google-Smtp-Source: ADKCNb7m7Ey1EGm6yZFG8zm3ZFyrSf3DWYFVwSzGkHPRGlaelLXcAyAPWQ8OIAecGTBQdLIDsbnlassu/O8w+K1XN3Q= X-Received: by 10.80.149.89 with SMTP id v25mr1065398eda.292.1504254391058; Fri, 01 Sep 2017 01:26:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.180.249 with HTTP; Fri, 1 Sep 2017 01:26:30 -0700 (PDT) In-Reply-To: <60ea6209-3b23-6398-da99-19326e24d8c2@suse.cz> References: <60ea6209-3b23-6398-da99-19326e24d8c2@suse.cz> From: Richard Biener Date: Fri, 01 Sep 2017 08:26:00 -0000 Message-ID: Subject: Re: [PATCH] Expand switch statements with a single (or none) non-default case. To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg00016.txt.bz2 On Fri, Sep 1, 2017 at 10:07 AM, Martin Li=C5=A1ka wrote: > On 08/30/2017 02:56 PM, Richard Biener wrote: >> On Wed, Aug 30, 2017 at 2:32 PM, Martin Li=C5=A1ka wrot= e: >>> On 08/30/2017 02:28 PM, Richard Biener wrote: >>>> On Wed, Aug 30, 2017 at 1:13 PM, Martin Li=C5=A1ka wr= ote: >>>>> Hi. >>>>> >>>>> Simple transformation of switch statements where degenerated switch c= an be interpreted >>>>> as gimple condition (or removed if having any non-default case). I or= iginally though >>>>> that we don't have switch statements without non-default cases, but P= R82032 shows we >>>>> can see it. >>>>> >>>>> Patch can bootstrap on ppc64le-redhat-linux and survives regression t= ests. >>>>> >>>>> Ready to be installed? >>>> >>>> While I guess this case is ok to handle here it would be nice if CFG c= leanup >>>> would do the same. I suppose find_taken_edge somehow doesn't work for >>>> this case even after my last enhancement? Or is CFG cleanup for some = reason >>>> not run? >>> >>> Do you mean both with # of non-default edges equal to 0 and 1? >>> Let me take a look. >> >> First and foremost 0. The case of 1 non-default and a default would >> need extra code. > > For the test-case I reduced, one needs: > > diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c > index b7593068ea9..13af516c6ac 100644 > --- a/gcc/tree-cfg.c > +++ b/gcc/tree-cfg.c > @@ -8712,7 +8712,7 @@ const pass_data pass_data_split_crit_edges =3D > PROP_no_crit_edges, /* properties_provided */ > 0, /* properties_destroyed */ > 0, /* todo_flags_start */ > - 0, /* todo_flags_finish */ > + TODO_cleanup_cfg, /* todo_flags_finish */ > }; > > class pass_split_crit_edges : public gimple_opt_pass > > And the code eliminates the problematic switch statement. Do you believe = it's the right approach > to add the clean up and preserve the assert in tree-switch-conversion.c? Eh, no. If you run cleanup-cfg after critical edge splitting they will be unsplit immediately, making it (mostly) a no-op. OTOH I wanted to eliminate that "pass" in favor of just calling split_critical_edges () where needed (that's already done in some places). > For the case with # of edges =3D=3D 1, should I place it to tree-cfg.c in= order to trigger it as a clean-up? I believe the code for edges =3D=3D 1 can reside in cleanup_control_expr_graph. Probably easiest from a flow perspective if we do the switch -> cond transform before the existing code handling cond and switch via find-taken-edge. > Thoughts? > > Martin > >> >> Richard. >> >>> Martin >>> >>>> >>>> Richard. >>>> >>>>> Martin >>>>> >>>>> gcc/ChangeLog: >>>>> >>>>> 2017-08-25 Martin Liska >>>>> >>>>> PR tree-optimization/82032 >>>>> * tree-switch-conversion.c (generate_high_low_equality): New >>>>> function. >>>>> (expand_degenerated_switch): Likewise. >>>>> (process_switch): Call expand_degenerated_switch. >>>>> (try_switch_expansion): Likewise. >>>>> (emit_case_nodes): Use generate_high_low_equality. >>>>> >>>>> gcc/testsuite/ChangeLog: >>>>> >>>>> 2017-08-25 Martin Liska >>>>> >>>>> PR tree-optimization/82032 >>>>> * gcc.dg/tree-ssa/pr68198.c: Update jump threading expectatio= ns. >>>>> * gcc.dg/tree-ssa/switch-expansion.c: New test. >>>>> * gcc.dg/tree-ssa/vrp34.c: Update scanned pattern. >>>>> * g++.dg/other/pr82032.C: New test. >>>>> --- >>>>> gcc/testsuite/g++.dg/other/pr82032.C | 36 +++++++ >>>>> gcc/testsuite/gcc.dg/tree-ssa/pr68198.c | 6 +- >>>>> gcc/testsuite/gcc.dg/tree-ssa/switch-expansion.c | 14 +++ >>>>> gcc/testsuite/gcc.dg/tree-ssa/vrp34.c | 5 +- >>>>> gcc/tree-switch-conversion.c | 123 +++++++++++++= +++++----- >>>>> 5 files changed, 152 insertions(+), 32 deletions(-) >>>>> create mode 100644 gcc/testsuite/g++.dg/other/pr82032.C >>>>> create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/switch-expansion.c >>>>> >>>>> >>> >