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 C39D63858D28 for ; Mon, 24 Apr 2023 12:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C39D63858D28 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-2a8b3ecf59fso40819831fa.0 for ; Mon, 24 Apr 2023 05:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682337833; x=1684929833; 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=vUeMijUjvCAyB1STygE6BPoEBdYDj4diYahoXge85BY=; b=ZCDGdpKvCrQdyr6QBxiOuSYAnug3sQP3j1fzcav1GGttt5YDUV+qv0CDauxSDgaIwA 8eaabU6NkjTq6+Hst6LofFWxvsN9tsWvSvbeClHZkliRApX4OAC25i3Ca8eVouHErrqZ AHjqkv8STFDcwoxT5kiSEc5OWbGpRDG9D0JIRJq3VRpVJAcVLKYjBQRNt2fxpMa5kb3Q KXQsoz0prznhVKaM9xrIFm+fpS7GPRe2ciB41Gzv2DTHELVVDlRKlE3hYz8+Sd0Th1+P MLe65fJYGDLdztAIS8xtrs6A5fXsmKE5hC4EFsvOtvHuFFf0dZoe1I6A2VP9aHrxYa00 PdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682337833; x=1684929833; 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=vUeMijUjvCAyB1STygE6BPoEBdYDj4diYahoXge85BY=; b=Q3OhFL00uXux6T2VTXU7IdBmolKHHIBKMVjDBgmveOAsoESEBZWVkKQiM5D4Csa/Di +YfFMNQltHNK9qs/Ixwu6b6fMmuxU4QrzggpToJz1AIThTGwuN8Zoo3ByuzBToulbWq8 7a81LpFyb3qtbejd+Pk0SIjlzR+M3bbn2T3wMMfV/0GXZ1JFJ99INL4KesmGtQgX/pek 1TXcrQ5YxJcvHpFt1h2rUatlcFEM61k7T35FN6tLwiLrs/3QY4kjMlv2EwO0GEBm4aaG Be5l3T3xAGhc34sNfnpOZQh938tpDgpkHY1UZHdAnA2yq3aUoX6Tn8jvn+JAFBBhHEKE eWug== X-Gm-Message-State: AAQBX9fy/UadYkI+4TDvRA9JZKdPSbsOdTg0anyUIz1LEdnXJUqTa3r9 /PQGDyTcqelyKlpsjevyJzLe9Ygrjdpmqq4h9lQ= X-Google-Smtp-Source: AKy350YaNufJ39tXXKW4dL1nzEwthqIm6PHm6G3bu63zp4nxoiiBa5jep54IyxOI2IXVCs+GnxzEpyKvfMZKkAhGerM= X-Received: by 2002:a2e:9c58:0:b0:2aa:4519:fa0 with SMTP id t24-20020a2e9c58000000b002aa45190fa0mr1871444ljj.34.1682337832888; Mon, 24 Apr 2023 05:03:52 -0700 (PDT) MIME-Version: 1.0 References: <20230422220921.452264-1-apinski@marvell.com> <20230422220921.452264-5-apinski@marvell.com> In-Reply-To: <20230422220921.452264-5-apinski@marvell.com> From: Richard Biener Date: Mon, 24 Apr 2023 14:02:26 +0200 Message-ID: Subject: Re: [PATCH 4/6] PHIOPT: Factor out some code from 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.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 Sun, Apr 23, 2023 at 12:11=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > This factors out the code checking if we have an empty bb > or one statement that feeds into the phi so it can be used > when adding diamond shaped bb form to match_simplify_replacement > in the next patch. Also allows for some improvements > in the next patches too. > > OK? Bootstrapped and tested on x86_64-linux-gnu. OK. > gcc/ChangeLog: > > * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): > New function. > (match_simplify_replacement): Call > empty_bb_or_one_feeding_into_p instead of doing it inline. > --- > gcc/tree-ssa-phiopt.cc | 106 ++++++++++++++++++++++++----------------- > 1 file changed, 62 insertions(+), 44 deletions(-) > > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index e4062f33efa..cb4d8788b56 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -940,6 +940,66 @@ gimple_simplify_phiopt (bool early_p, tree type, gim= ple *comp_stmt, > return NULL; > } > > +/* empty_bb_or_one_feeding_into_p returns true if bb was empty basic blo= ck > + or it has one cheap preparation statement that feeds into the PHI > + statement and it sets STMT to that statement. */ > +static bool > +empty_bb_or_one_feeding_into_p (basic_block bb, > + gimple *phi, > + gimple *&stmt) > +{ > + stmt =3D nullptr; > + gimple *stmt_to_move =3D nullptr; > + > + if (empty_block_p (bb)) > + return true; > + > + if (!single_pred_p (bb)) > + return false; > + > + /* The middle bb cannot have phi nodes as we don't > + move those assignments yet. */ > + if (!gimple_seq_empty_p (phi_nodes (bb))) > + return false; > + > + stmt_to_move =3D last_and_only_stmt (bb); > + if (!stmt_to_move) > + return false; > + > + if (gimple_vuse (stmt_to_move)) > + return false; > + > + if (gimple_could_trap_p (stmt_to_move) > + || gimple_has_side_effects (stmt_to_move)) > + return false; > + > + if (gimple_uses_undefined_value_p (stmt_to_move)) > + return false; > + > + /* Allow assignments and not no calls. > + As const calls don't match any of the above, yet they could > + still have some side-effects - they could contain > + gimple_could_trap_p statements, like floating point > + exceptions or integer division by zero. See PR70586. > + FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p > + should handle this. */ > + if (!is_gimple_assign (stmt_to_move)) > + return false; > + > + tree lhs =3D gimple_assign_lhs (stmt_to_move); > + gimple *use_stmt; > + use_operand_p use_p; > + > + /* Allow only a statement which feeds into the other stmt. */ > + if (!lhs || TREE_CODE (lhs) !=3D SSA_NAME > + || !single_imm_use (lhs, &use_p, &use_stmt) > + || use_stmt !=3D phi) > + return false; > + > + stmt =3D stmt_to_move; > + return true; > +} > + > /* The function match_simplify_replacement does the main work of doing = the > replacement using match and simplify. Return true if the replacemen= t is done. > Otherwise return false. > @@ -965,50 +1025,8 @@ match_simplify_replacement (basic_block cond_bb, ba= sic_block middle_bb, > > /* If the basic block only has a cheap preparation statement, > allow it and move it once the transformation is done. */ > - if (!empty_block_p (middle_bb)) > - { > - if (!single_pred_p (middle_bb)) > - return false; > - > - /* The middle bb cannot have phi nodes as we don't > - move those assignments yet. */ > - if (!gimple_seq_empty_p (phi_nodes (middle_bb))) > - return false; > - > - stmt_to_move =3D last_and_only_stmt (middle_bb); > - if (!stmt_to_move) > - return false; > - > - if (gimple_vuse (stmt_to_move)) > - return false; > - > - if (gimple_could_trap_p (stmt_to_move) > - || gimple_has_side_effects (stmt_to_move)) > - return false; > - > - if (gimple_uses_undefined_value_p (stmt_to_move)) > - return false; > - > - /* Allow assignments and not no calls. > - As const calls don't match any of the above, yet they could > - still have some side-effects - they could contain > - gimple_could_trap_p statements, like floating point > - exceptions or integer division by zero. See PR70586. > - FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p > - should handle this. */ > - if (!is_gimple_assign (stmt_to_move)) > - return false; > - > - tree lhs =3D gimple_assign_lhs (stmt_to_move); > - gimple *use_stmt; > - use_operand_p use_p; > - > - /* Allow only a statement which feeds into the phi. */ > - if (!lhs || TREE_CODE (lhs) !=3D SSA_NAME > - || !single_imm_use (lhs, &use_p, &use_stmt) > - || use_stmt !=3D phi) > - return false; > - } > + if (!empty_bb_or_one_feeding_into_p (middle_bb, phi, stmt_to_move)) > + 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 > -- > 2.39.1 >