From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id 16EEE385841E for ; Thu, 27 Apr 2023 10:51:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16EEE385841E 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-x22b.google.com with SMTP id 38308e7fff4ca-2a8bcfbf276so77416791fa.3 for ; Thu, 27 Apr 2023 03:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682592701; x=1685184701; 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=JOzp/7IdZ6zE84Qp2k1doMgE8SPOFgW2rRkFwUTTZRE=; b=UMtVu6KfleUKjoXx96WIb+3fLg8WdeZ7/x6/rn4jWuENwuFwLwooj8dKaZbdK2f9SY Kyh9Z41bJs9Px12dYxgpGxalcQFGT1NBlusEo1Mm3qDtiU/ZlLKvuuFbu4Ja+lvtFqGK IXb6qRRiXB4+VBQ5OxV1JvttAXP9nMN0VtyLqaRFb9Mgn9zrwxynzYCI0GO08bmhdbV0 E541v/CBPCBQP1F4Tb5ywBywOq4/sEAefCdMtD9Zf5pZVS1z8Sl6UB1JAwXHePi16G2Z 7ifH6vPsZRcNtkmNU8k0waXsEuADGVW0z/F0KeMs0QvE8+pgsu/ktqn9YX8jE3DV4AEn imWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682592701; x=1685184701; 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=JOzp/7IdZ6zE84Qp2k1doMgE8SPOFgW2rRkFwUTTZRE=; b=WSAWO/7ssrVF4z5RdO2bQHoXfp66/FRb4aASdU4iNKFvjmMcNHdwo8a2wC2yr6mmsq pXN8WfnpqF9LzklyFBH0bCSUUjmts/FVqcnDfmMoavn9jh4CfBNLiEWkmVVbliUd/Eko FzwsEkdMYjbrG6MMOUZhcHAXL41kJJglFP4pQrJNvIfh3ZCr+TesAbqOXMTPGqdNO7t9 nexbcg1PeYXTfllBgz0xba6MLospKemGZqYQj3xojlae+/p7ZSvzet4IjAvYPIOBhbeJ 4v23KNXmIu74HleluxCqHtrjDx9QC/WR9FR+8Rzyf6DxncH0U1sICzkROZiRfa5kX6Xi HX2A== X-Gm-Message-State: AC+VfDz/+p2rp5CUYWXITJxDri3oxn50SJ30z7OGgS9uZP7/iiLPtU7D TgtwNu5KoxDZ2YKKQgc+OLalamwJ5NHvQDgF95o= X-Google-Smtp-Source: ACHHUZ4uLBeBzZMPA4MRp85/VtDNQUqyCXRc8IyBjHBo+XC44D09PqfJ9+xioDA0AmCTJwoF25OF5SCQWuVpvQBTUgE= X-Received: by 2002:a2e:9d0c:0:b0:2ab:19a0:667b with SMTP id t12-20020a2e9d0c000000b002ab19a0667bmr508425lji.0.1682592701366; Thu, 27 Apr 2023 03:51:41 -0700 (PDT) MIME-Version: 1.0 References: <20230424213011.528181-1-apinski@marvell.com> <20230424213011.528181-4-apinski@marvell.com> In-Reply-To: <20230424213011.528181-4-apinski@marvell.com> From: Richard Biener Date: Thu, 27 Apr 2023 12:50:12 +0200 Message-ID: Subject: Re: [PATCH 3/7] PHIOPT: Move store_elim_worker into pass_cselim::execute 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.0 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 Mon, Apr 24, 2023 at 11:31=E2=80=AFPM Andrew Pinski via Gcc-patches wrote: > > This simple patch moves the body of store_elim_worker > direclty into pass_cselim::execute. > > Also removes unneeded prototypes too. > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. > gcc/ChangeLog: > > * tree-ssa-phiopt.cc (cond_store_replacement): Remove > prototype. > (cond_if_else_store_replacement): Likewise. > (get_non_trapping): Likewise. > (store_elim_worker): Move into ... > (pass_cselim::execute): This. > --- > gcc/tree-ssa-phiopt.cc | 250 ++++++++++++++++++++--------------------- > 1 file changed, 119 insertions(+), 131 deletions(-) > > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index d232fd9b551..fb2d2c9fc1a 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -55,11 +55,6 @@ along with GCC; see the file COPYING3. If not see > #include "tree-ssa-propagate.h" > #include "tree-ssa-dce.h" > > -static bool cond_store_replacement (basic_block, basic_block, edge, edge= , > - hash_set *); > -static bool cond_if_else_store_replacement (basic_block, basic_block, ba= sic_block); > -static hash_set * get_non_trapping (); > - > /* Return the singleton PHI in the SEQ of PHIs for edges E0 and E1. */ > > static gphi * > @@ -87,130 +82,6 @@ single_non_singleton_phi_for_edges (gimple_seq seq, e= dge e0, edge e1) > return phi; > } > > -/* The core routine of conditional store replacement. */ > -static unsigned int > -store_elim_worker (void) > -{ > - basic_block bb; > - basic_block *bb_order; > - unsigned n, i; > - bool cfgchanged =3D false; > - hash_set *nontrap =3D 0; > - > - calculate_dominance_info (CDI_DOMINATORS); > - > - /* Calculate the set of non-trapping memory accesses. */ > - nontrap =3D get_non_trapping (); > - > - /* Search every basic block for COND_EXPR we may be able to optimize. > - > - We walk the blocks in order that guarantees that a block with > - a single predecessor is processed before the predecessor. > - This ensures that we collapse inner ifs before visiting the > - outer ones, and also that we do not try to visit a removed > - block. */ > - bb_order =3D single_pred_before_succ_order (); > - n =3D n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; > - > - for (i =3D 0; i < n; i++) > - { > - basic_block bb1, bb2; > - edge e1, e2; > - bool diamond_p =3D false; > - > - bb =3D bb_order[i]; > - > - /* Check to see if the last statement is a GIMPLE_COND. */ > - gcond *cond_stmt =3D safe_dyn_cast (*gsi_last_bb (bb)); > - if (!cond_stmt) > - continue; > - > - e1 =3D EDGE_SUCC (bb, 0); > - bb1 =3D e1->dest; > - e2 =3D EDGE_SUCC (bb, 1); > - bb2 =3D e2->dest; > - > - /* We cannot do the optimization on abnormal edges. */ > - if ((e1->flags & EDGE_ABNORMAL) !=3D 0 > - || (e2->flags & EDGE_ABNORMAL) !=3D 0) > - continue; > - > - /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ > - if (EDGE_COUNT (bb1->succs) =3D=3D 0 > - || EDGE_COUNT (bb2->succs) =3D=3D 0) > - continue; > - > - /* Find the bb which is the fall through to the other. */ > - if (EDGE_SUCC (bb1, 0)->dest =3D=3D bb2) > - ; > - else if (EDGE_SUCC (bb2, 0)->dest =3D=3D bb1) > - { > - std::swap (bb1, bb2); > - std::swap (e1, e2); > - } > - else if (EDGE_SUCC (bb1, 0)->dest =3D=3D EDGE_SUCC (bb2, 0)->dest > - && single_succ_p (bb2)) > - { > - diamond_p =3D true; > - e2 =3D EDGE_SUCC (bb2, 0); > - /* Make sure bb2 is just a fall through. */ > - if ((e2->flags & EDGE_FALLTHRU) =3D=3D 0) > - continue; > - } > - else > - continue; > - > - e1 =3D EDGE_SUCC (bb1, 0); > - > - /* Make sure that bb1 is just a fall through. */ > - if (!single_succ_p (bb1) > - || (e1->flags & EDGE_FALLTHRU) =3D=3D 0) > - continue; > - > - if (diamond_p) > - { > - basic_block bb3 =3D e1->dest; > - > - /* Only handle sinking of store from 2 bbs only, > - The middle bbs don't need to come from the > - if always since we are sinking rather than > - hoisting. */ > - if (EDGE_COUNT (bb3->preds) !=3D 2) > - continue; > - if (cond_if_else_store_replacement (bb1, bb2, bb3)) > - cfgchanged =3D true; > - continue; > - } > - > - /* Also make sure that bb1 only have one predecessor and that it > - is bb. */ > - if (!single_pred_p (bb1) > - || single_pred (bb1) !=3D bb) > - continue; > - > - /* bb1 is the middle block, bb2 the join block, bb the split block= , > - e1 the fallthrough edge from bb1 to bb2. We can't do the > - optimization if the join block has more than two predecessors. = */ > - if (EDGE_COUNT (bb2->preds) > 2) > - continue; > - if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) > - cfgchanged =3D true; > - } > - > - free (bb_order); > - > - delete nontrap; > - /* If the CFG has changed, we should cleanup the CFG. */ > - if (cfgchanged) > - { > - /* In cond-store replacement we have added some loads on edges > - and new VOPS (as we moved the store, and created a load). */ > - gsi_commit_edge_inserts (); > - return TODO_cleanup_cfg | TODO_update_ssa_only_virtuals; > - } > - return 0; > -} > - > /* Replace PHI node element whose edge is E in block BB with variable NE= W. > Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK > is known to have two edges, one of which must reach BB). */ > @@ -4403,13 +4274,130 @@ make_pass_cselim (gcc::context *ctxt) > unsigned int > pass_cselim::execute (function *) > { > - unsigned todo; > + basic_block bb; > + basic_block *bb_order; > + unsigned n, i; > + bool cfgchanged =3D false; > + hash_set *nontrap =3D 0; > + unsigned todo =3D 0; > + > /* ??? We are not interested in loop related info, but the following > will create it, ICEing as we didn't init loops with pre-headers. > An interfacing issue of find_data_references_in_bb. */ > loop_optimizer_init (LOOPS_NORMAL); > scev_initialize (); > - todo =3D store_elim_worker (); > + > + calculate_dominance_info (CDI_DOMINATORS); > + > + /* Calculate the set of non-trapping memory accesses. */ > + nontrap =3D get_non_trapping (); > + > + /* Search every basic block for COND_EXPR we may be able to optimize. > + > + We walk the blocks in order that guarantees that a block with > + a single predecessor is processed before the predecessor. > + This ensures that we collapse inner ifs before visiting the > + outer ones, and also that we do not try to visit a removed > + block. */ > + bb_order =3D single_pred_before_succ_order (); > + n =3D n_basic_blocks_for_fn (cfun) - NUM_FIXED_BLOCKS; > + > + for (i =3D 0; i < n; i++) > + { > + basic_block bb1, bb2; > + edge e1, e2; > + bool diamond_p =3D false; > + > + bb =3D bb_order[i]; > + > + /* Check to see if the last statement is a GIMPLE_COND. */ > + gcond *cond_stmt =3D safe_dyn_cast (*gsi_last_bb (bb)); > + if (!cond_stmt) > + continue; > + > + e1 =3D EDGE_SUCC (bb, 0); > + bb1 =3D e1->dest; > + e2 =3D EDGE_SUCC (bb, 1); > + bb2 =3D e2->dest; > + > + /* We cannot do the optimization on abnormal edges. */ > + if ((e1->flags & EDGE_ABNORMAL) !=3D 0 > + || (e2->flags & EDGE_ABNORMAL) !=3D 0) > + continue; > + > + /* If either bb1's succ or bb2 or bb2's succ is non NULL. */ > + if (EDGE_COUNT (bb1->succs) =3D=3D 0 > + || EDGE_COUNT (bb2->succs) =3D=3D 0) > + continue; > + > + /* Find the bb which is the fall through to the other. */ > + if (EDGE_SUCC (bb1, 0)->dest =3D=3D bb2) > + ; > + else if (EDGE_SUCC (bb2, 0)->dest =3D=3D bb1) > + { > + std::swap (bb1, bb2); > + std::swap (e1, e2); > + } > + else if (EDGE_SUCC (bb1, 0)->dest =3D=3D EDGE_SUCC (bb2, 0)->dest > + && single_succ_p (bb2)) > + { > + diamond_p =3D true; > + e2 =3D EDGE_SUCC (bb2, 0); > + /* Make sure bb2 is just a fall through. */ > + if ((e2->flags & EDGE_FALLTHRU) =3D=3D 0) > + continue; > + } > + else > + continue; > + > + e1 =3D EDGE_SUCC (bb1, 0); > + > + /* Make sure that bb1 is just a fall through. */ > + if (!single_succ_p (bb1) > + || (e1->flags & EDGE_FALLTHRU) =3D=3D 0) > + continue; > + > + if (diamond_p) > + { > + basic_block bb3 =3D e1->dest; > + > + /* Only handle sinking of store from 2 bbs only, > + The middle bbs don't need to come from the > + if always since we are sinking rather than > + hoisting. */ > + if (EDGE_COUNT (bb3->preds) !=3D 2) > + continue; > + if (cond_if_else_store_replacement (bb1, bb2, bb3)) > + cfgchanged =3D true; > + continue; > + } > + > + /* Also make sure that bb1 only have one predecessor and that it > + is bb. */ > + if (!single_pred_p (bb1) > + || single_pred (bb1) !=3D bb) > + continue; > + > + /* bb1 is the middle block, bb2 the join block, bb the split block= , > + e1 the fallthrough edge from bb1 to bb2. We can't do the > + optimization if the join block has more than two predecessors. = */ > + if (EDGE_COUNT (bb2->preds) > 2) > + continue; > + if (cond_store_replacement (bb1, bb2, e1, e2, nontrap)) > + cfgchanged =3D true; > + } > + > + free (bb_order); > + > + delete nontrap; > + /* If the CFG has changed, we should cleanup the CFG. */ > + if (cfgchanged) > + { > + /* In cond-store replacement we have added some loads on edges > + and new VOPS (as we moved the store, and created a load). */ > + gsi_commit_edge_inserts (); > + todo =3D TODO_cleanup_cfg | TODO_update_ssa_only_virtuals; > + } > scev_finalize (); > loop_optimizer_finalize (); > return todo; > -- > 2.39.1 >