From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id EDBB83856944 for ; Mon, 24 Apr 2023 12:09:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDBB83856944 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2a8baeac4d1so40864091fa.1 for ; Mon, 24 Apr 2023 05:09:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682338153; x=1684930153; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qSoHnq5zD/Xmf7rNClMm7kVQHgNcfyLEOVY6pUt36S0=; b=dvMvn2nBuMYEKH69LIcDMm/EOYjEbAWe4v1KUHuJn4VHtZiHcZpgZvCHbOobGC38MX bXzmQn5DqYtK4dB1nc7M7oMk7UMrIbs+Vh2VPCYWzBRxSBq2qkjER/r61z1k784TfFfT S2z8rEfzu8BBaYlqhm/YvEVfmRSJ4jBM+HviRQSDwyxxwGGb0DMQuNqkJdP9OAuMlE8j rSnz3pJP0RHAeYL//qwe4Ib7doqOaktEDmPzDEBhEobO7p41BoEOTMgkUnp1eDXKITR/ +Y+bkRQLSrc9jae2f5vcZuNTRnW2RN/NP4wCeqYW1dlCPVQtoFkwaEryL4OUAn7iILCx pSCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682338153; x=1684930153; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qSoHnq5zD/Xmf7rNClMm7kVQHgNcfyLEOVY6pUt36S0=; b=SvYrMAF6CnG3O4MUiSIzM0T4Tetkh56/xkzirIuOEbrBMg70ukNWIte/x3QcLwoBpK 5gSy8uMrLCoeZG4V2BfOGHsaVivf8FZnZe2zrcHCgusQ5qWJO3MMkKL6Knwq0bC1ujRc IGUO4M1fPjNfZZ1rkraB9YgKS6RMfuuEp7jSa6JlvUbNmv11z+l6xNyV/XAl70s5cjSs YNGpEZovOlAUFOP+C2W6FhvuWjcCp1LdbPLwJ3UzbJCnQHhpAvWZqqkI0bEhekFNttCP nSErC3bMA/smXE6da0oVQ4MPhr2ZTtlnI3Z+SdOaRrmMJJ/06RoVMwXcTNrZcFy/1zsO Gj+Q== X-Gm-Message-State: AAQBX9ezyz40Ysu1eil961JjirDxjEaXz3R02EfgJdjy26ytK1itYB5F hhmcPUli4ibofULm/wd+MjF2AFRknOTOOwRR5wRP+X+4 X-Google-Smtp-Source: AKy350Zwaz4jkoJVkhdqDlyP9yS4Hl+fVZIQfdU2SYA4FhJGcykUQVaXbcG5g5Dra+Ppa+oYL1sivd23vJwYnwD9Pik= X-Received: by 2002:a2e:920b:0:b0:2a8:d08e:b7dc with SMTP id k11-20020a2e920b000000b002a8d08eb7dcmr2381312ljg.28.1682338153464; Mon, 24 Apr 2023 05:09:13 -0700 (PDT) MIME-Version: 1.0 References: <20230422220921.452264-1-apinski@marvell.com> <20230422220921.452264-7-apinski@marvell.com> In-Reply-To: <20230422220921.452264-7-apinski@marvell.com> From: Richard Biener Date: Mon, 24 Apr 2023 14:07:48 +0200 Message-ID: Subject: Re: [PATCH 6/6] PHIOPT: Add support for diamond shaped bb to match_simplify_replacement To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 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 List-Id: On Sun, Apr 23, 2023 at 12:13=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > This adds diamond shaped form of basic blocks to match_simplify_replaceme= nt. > This is the patch is the start of removing/moving all > of what minmax_replacement does to match.pd to reduce the code duplicatio= n. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. thanks, Richard. > Note phi-opt-{23,24}.c testcase had an incorrect xfail as there should > have been 2 if still because f4/f5 would not be transformed as -ABS is > not allowable during early phi-opt. > > gcc/ChangeLog: > > * tree-ssa-phiopt.cc (match_simplify_replacement): Add new argume= nts > and support diamond shaped basic block form. > (tree_ssa_phiopt_worker): Update call to match_simplify_replaceme= nt > > gcc/testsuite/ChangeLog: > > * gcc.dg/tree-ssa/phi-opt-23.c: Update testcase. > * gcc.dg/tree-ssa/phi-opt-24.c: Likewise. > --- > gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c | 4 +-- > gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c | 4 +-- > gcc/tree-ssa-phiopt.cc | 37 ++++++++++++++++++---- > 3 files changed, 35 insertions(+), 10 deletions(-) > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c b/gcc/testsuite/g= cc.dg/tree-ssa/phi-opt-23.c > index ff658cd16a7..86aab955d5e 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c > @@ -38,7 +38,7 @@ int f5(int A) > return -A; > } > > -/* These should be optimized in phiopt1 but is confused by predicts. */ > -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ > +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ > +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ > > diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c b/gcc/testsuite/g= cc.dg/tree-ssa/phi-opt-24.c > index eb89decb4bf..bd8308efa0e 100644 > --- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c > +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c > @@ -38,7 +38,7 @@ float f5(float A) > return -A; > } > > -/* These should be optimized in phiopt1 but is confused by predicts. */ > -/* { dg-final { scan-tree-dump-not "if" "phiopt1" { xfail *-*-* } } } */ > +/* f4 and f5 are not allowed to be optimized in early phi-opt. */ > +/* { dg-final { scan-tree-dump-times "if" 2 "phiopt1" } } */ > /* { dg-final { scan-tree-dump-not "if" "phiopt2" } } */ > > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index ffd6a4e6f35..757e44692ed 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -57,8 +57,8 @@ along with GCC; see the file COPYING3. If not see > > static bool two_value_replacement (basic_block, basic_block, edge, gphi = *, > tree, tree); > -static bool match_simplify_replacement (basic_block, basic_block, > - edge, edge, gphi *, tree, tree, b= ool); > +static bool match_simplify_replacement (basic_block, basic_block, basic_= block, > + edge, edge, gphi *, tree, tree, b= ool, bool); > static gphi *factor_out_conditional_conversion (edge, edge, gphi *, tree= , tree, > gimple *); > static int value_replacement (basic_block, basic_block, > @@ -304,9 +304,8 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool do_h= oist_loads, bool early_p) > && !diamond_p > && two_value_replacement (bb, bb1, e2, phi, arg0, arg1)) > cfgchanged =3D true; > - else if (!diamond_p > - && match_simplify_replacement (bb, bb1, e1, e2, phi, > - arg0, arg1, early_p)) > + else if (match_simplify_replacement (bb, bb1, bb2, e1, e2, phi, > + arg0, arg1, early_p, diamond_p= )) > cfgchanged =3D true; > else if (!early_p > && !diamond_p > @@ -1026,8 +1025,10 @@ empty_bb_or_one_feeding_into_p (basic_block bb, > > static bool > match_simplify_replacement (basic_block cond_bb, basic_block middle_bb, > + basic_block middle_bb_alt, > edge e0, edge e1, gphi *phi, > - tree arg0, tree arg1, bool early_p) > + tree arg0, tree arg1, bool early_p, > + bool threeway_p) > { > gimple *stmt; > gimple_stmt_iterator gsi; > @@ -1035,6 +1036,7 @@ match_simplify_replacement (basic_block cond_bb, ba= sic_block middle_bb, > gimple_seq seq =3D NULL; > tree result; > gimple *stmt_to_move =3D NULL; > + gimple *stmt_to_move_alt =3D NULL; > auto_bitmap inserted_exprs; > > /* Special case A ? B : B as this will always simplify to B. */ > @@ -1046,6 +1048,12 @@ match_simplify_replacement (basic_block cond_bb, b= asic_block middle_bb, > if (!empty_bb_or_one_feeding_into_p (middle_bb, phi, stmt_to_move)) > return false; > > + if (threeway_p > + && middle_bb !=3D middle_bb_alt > + && !empty_bb_or_one_feeding_into_p (middle_bb_alt, phi, > + stmt_to_move_alt)) > + return false; > + > /* At this point we know we have a GIMPLE_COND with two successors. > One successor is BB, the other successor is an empty block which > falls through into BB. > @@ -1110,6 +1118,23 @@ match_simplify_replacement (basic_block cond_bb, b= asic_block middle_bb, > reset_flow_sensitive_info (name); > } > > + if (stmt_to_move_alt) > + { > + if (dump_file && (dump_flags & TDF_DETAILS)) > + { > + fprintf (dump_file, "statement un-sinked:\n"); > + print_gimple_stmt (dump_file, stmt_to_move_alt, 0, > + TDF_VOPS|TDF_MEMSYMS); > + } > + > + tree name =3D gimple_get_lhs (stmt_to_move_alt); > + // Mark the name to be renamed if there is one. > + bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (name)); > + gimple_stmt_iterator gsi1 =3D gsi_for_stmt (stmt_to_move_alt); > + gsi_move_before (&gsi1, &gsi); > + reset_flow_sensitive_info (name); > + } > + > replace_phi_edge_with_variable (cond_bb, e1, phi, result, inserted_exp= rs); > > /* Add Statistic here even though replace_phi_edge_with_variable alrea= dy > -- > 2.39.1 >