From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZR3nGAqBz1/NbAAAWB0awg (envelope-from ) for ; Tue, 08 Dec 2020 08:35:06 -0500 Received: by simark.ca (Postfix, from userid 112) id 5A59B1F096; Tue, 8 Dec 2020 08:35:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI,RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id DD14D1E590 for ; Tue, 8 Dec 2020 08:35:05 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 895073850432; Tue, 8 Dec 2020 13:35:05 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 28AE73850432 for ; Tue, 8 Dec 2020 13:35:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 28AE73850432 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3DED5AC9A for ; Tue, 8 Dec 2020 13:35:02 +0000 (UTC) Subject: Re: [PATCH] if-to-switch: fix matching of negative conditions From: =?UTF-8?Q?Martin_Li=c5=a1ka?= To: gdb-patches@sourceware.org References: Message-ID: <647372df-7b4f-8931-a492-2b0a006d1900@suse.cz> Date: Tue, 8 Dec 2020 14:35:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Whoops, sorry, bad mailing list. On 12/8/20 2:22 PM, Martin Liška wrote: > We must be careful which edge we follow for conditions > of a negative form (index != 2). > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? > Thanks, > Martin > > gcc/ChangeLog: > >     PR tree-optimization/98182 >     * gimple-if-to-switch.cc (pass_if_to_switch::execute): Request >     chain linkage through false edges only. > > gcc/testsuite/ChangeLog: > >     PR tree-optimization/98182 >     * gcc.dg/tree-ssa/if-to-switch-10.c: New test. >     * gcc.dg/tree-ssa/pr98182.c: New test. > --- >  gcc/gimple-if-to-switch.cc                    |  6 +++ >  .../gcc.dg/tree-ssa/if-to-switch-10.c         | 44 +++++++++++++++++++ >  gcc/testsuite/gcc.dg/tree-ssa/pr98182.c       | 18 ++++++++ >  3 files changed, 68 insertions(+) >  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-10.c >  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr98182.c > > diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc > index 8e1043ae7c4..311f6f6ac97 100644 > --- a/gcc/gimple-if-to-switch.cc > +++ b/gcc/gimple-if-to-switch.cc > @@ -522,6 +522,12 @@ pass_if_to_switch::execute (function *fun) >            if (!info2 || info->m_ranges[0].exp != info2->m_ranges[0].exp) >          break; > > +          /* It is important that the blocks are linked through FALSE_EDGE. > +         For an expression of index != VALUE, true and false edges > +         are flipped.  */ > +          if (info2->m_false_edge != e) > +        break; > + >            chain->m_entries.safe_push (info2); >            bitmap_set_bit (seen_bbs, e->src->index); >            info = info2; > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-10.c b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-10.c > new file mode 100644 > index 00000000000..7b8da1c9f3c > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/if-to-switch-10.c > @@ -0,0 +1,44 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-iftoswitch-optimized" } */ > + > +int global; > +int foo (); > + > +int main(int argc, char **argv) > +{ > +  if (argc != 1) > +    { > +      if (argc != 2) > +    { > +      if (argc == 3) > +        { > +          foo (); > +          foo (); > +        } > +      else if (argc == 4) > +        { > +          foo (); > +        } > +      else if (argc == 5) > +        { > +          global = 2; > +        } > +      else > +        global -= 123; > +    } > +      else > +    { > +      global += 1; > +    } > +    } > +  else > +    foo (); > + > + > +  global -= 12; > +  return 0; > +} > + > +/* { dg-final { scan-tree-dump "Canonical GIMPLE case clusters: 1 2 3 4 5" "iftoswitch" } } */ > +/* { dg-final { scan-tree-dump "Condition chain with \[^\n\r]\* BBs transformed into a switch statement." "iftoswitch" } } */ > + > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr98182.c b/gcc/testsuite/gcc.dg/tree-ssa/pr98182.c > new file mode 100644 > index 00000000000..29a547e3788 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr98182.c > @@ -0,0 +1,18 @@ > +/* PR tree-optimization/98182 */ > +/* { dg-do compile } */ > +/* { dg-options "-O1 --param case-values-threshold=1 -fdump-tree-iftoswitch-optimized" } */ > + > +int global; > +int foo (); > + > +int main(int argc, char **argv) > +{ > +  if (argc != 1) > +    __builtin_abort (); > +  else if (argc != 2) > +    __builtin_abort (); > +  else > +    return 0; > +} > + > +/* { dg-final { scan-tree-dump-not "Condition chain" "iftoswitch" } } */