From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by sourceware.org (Postfix) with ESMTPS id 85BC53858D39 for ; Fri, 1 Jul 2022 06:40:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85BC53858D39 Received: by mail-qv1-xf33.google.com with SMTP id t16so3257334qvh.1 for ; Thu, 30 Jun 2022 23:40:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=F9A3809uSdqrsHuo3Au3xJ2+Tz7w/zlB1xsnL3B6LI8=; b=U6E801Sp+uwhHBvUzuKWdlFcYExjOq9L+tMs7DZJlXS0m4gCH4igq16wFRHhknutOU pc+qOzHoFIC+/ct1qso/+kITfyoPzHR8kukXlYY9FyuJm8speJa1H7EJJOuPAiJ/Z0nJ ZHHAnpfIQoBq+FyylHOFb9BPfjj6C3tIc7N+5moV41KkE7bn54BPMMlEu006lbtXCG/2 byQZF1R1nBKtQ8TivVLAnoLtTsFfJZ7EYJT4mFJ3gIp8ECn311UoqOvBYYw31SOzaSH+ RKjxJ7jMx2bdcv+Om6ot+fMO0Jydxstk8MCzA3RW9QHhm+MMDguy4YMhTVdYaXV7qFFp 1bvQ== X-Gm-Message-State: AJIora9Z2D/hp1MXdUBJViTZlti1JT1LMLw2/Vzax7D4ptJqVqsYtruj mloK1PvYxvIX/jL4bBCrmb7xLH7ymJQLdFYuRlTzhUmj X-Google-Smtp-Source: AGRyM1tjbjyMPFgrMYSFvcr3o2cqaAMx2DuIBEQMPJ4cHhaMBKx+BBz4RFUtCFd7+8kabfhO5KYHEUmQSRwrvyXpjsw= X-Received: by 2002:a05:622a:4cd:b0:31d:26a1:2536 with SMTP id q13-20020a05622a04cd00b0031d26a12536mr10395156qtx.626.1656657601893; Thu, 30 Jun 2022 23:40:01 -0700 (PDT) MIME-Version: 1.0 References: <1a717e7d-f0c7-14d8-d0cf-8d3e4f7ecbd2@suse.cz> In-Reply-To: <1a717e7d-f0c7-14d8-d0cf-8d3e4f7ecbd2@suse.cz> From: Richard Biener Date: Fri, 1 Jul 2022 08:39:50 +0200 Message-ID: Subject: Re: [PATCH] if-to-switch: properly allow side effects only for first condition To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches , =?UTF-8?B?eGlvbmdodWx1byjnvZfpm4TomY4p?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2022 06:40:04 -0000 On Thu, Jun 30, 2022 at 4:29 PM Martin Li=C5=A1ka wrote: > > Properly allow side effects only for a first BB in a condition chain. > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? OK > Thanks, > Martin > > PR tree-optimization/106126 > > gcc/ChangeLog: > > * gimple-if-to-switch.cc (struct condition_info): Save > has_side_effect. > (find_conditions): Parse all BBs. > (pass_if_to_switch::execute): Allow only side effects for first > BB. > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/pr106126.c: New test. > --- > gcc/gimple-if-to-switch.cc | 20 +++++++++++--------- > gcc/testsuite/gcc.dg/tree-ssa/pr106126.c | 12 ++++++++++++ > 2 files changed, 23 insertions(+), 9 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr106126.c > > diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc > index 70daae2003c..4441206c481 100644 > --- a/gcc/gimple-if-to-switch.cc > +++ b/gcc/gimple-if-to-switch.cc > @@ -61,9 +61,11 @@ struct condition_info > { > typedef auto_vec> mapping_vec; > > - condition_info (gcond *cond): m_cond (cond), m_bb (gimple_bb (cond)), > - m_forwarder_bb (NULL), m_ranges (), m_true_edge (NULL), m_false_edge= (NULL), > - m_true_edge_phi_mapping (), m_false_edge_phi_mapping () > + condition_info (gcond *cond, bool has_side_effect): m_cond (cond), > + m_bb (gimple_bb (cond)), m_forwarder_bb (NULL), m_ranges (), > + m_true_edge (NULL), m_false_edge (NULL), > + m_true_edge_phi_mapping (), m_false_edge_phi_mapping (), > + m_has_side_effect (has_side_effect) > { > m_ranges.create (0); > } > @@ -80,6 +82,7 @@ struct condition_info > edge m_false_edge; > mapping_vec m_true_edge_phi_mapping; > mapping_vec m_false_edge_phi_mapping; > + bool m_has_side_effect; > }; > > /* Recond PHI mapping for an original edge E and save these into vector = VEC. */ > @@ -389,16 +392,11 @@ find_conditions (basic_block bb, > if (cond =3D=3D NULL) > return; > > - /* An empty conditions_in_bbs indicates we are processing the first > - basic-block then no need check side effect. */ > - if (!conditions_in_bbs->is_empty () && !no_side_effect_bb (bb)) > - return; > - > tree lhs =3D gimple_cond_lhs (cond); > tree rhs =3D gimple_cond_rhs (cond); > tree_code code =3D gimple_cond_code (cond); > > - condition_info *info =3D new condition_info (cond); > + condition_info *info =3D new condition_info (cond, !no_side_effect_bb = (bb)); > > gassign *def; > if (code =3D=3D NE_EXPR > @@ -536,6 +534,10 @@ pass_if_to_switch::execute (function *fun) > if ((*info2)->m_false_edge !=3D e) > break; > > + /* Only the first BB in a chain can have a side effect. */ > + if (info->m_has_side_effect) > + break; > + > chain->m_entries.safe_push (*info2); > bitmap_set_bit (seen_bbs, e->src->index); > info =3D *info2; > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr106126.c b/gcc/testsuite/gcc= .dg/tree-ssa/pr106126.c > new file mode 100644 > index 00000000000..2f0fd44164b > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr106126.c > @@ -0,0 +1,12 @@ > +/* PR tree-optimization/106126 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2" } */ > + > +char *var_1; > +void pool_conda_matchspec() { > + for (; var_1 && *var_1 && > + *var_1 !=3D '<' && *var_1 !=3D '>' && > + *var_1 !=3D '!' && *var_1 !=3D '~';) > + if (*var_1 >=3D 'A' && *var_1 <=3D 'Z') > + *var_1 +=3D 'A'; > +} > -- > 2.36.1 >