From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 9D7393858D32 for ; Wed, 19 Jul 2023 08:33:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D7393858D32 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-x22d.google.com with SMTP id 38308e7fff4ca-2b703a0453fso107728541fa.3 for ; Wed, 19 Jul 2023 01:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689755590; x=1692347590; 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=5RXWxXthawWjmUY9dkdjn2rnAJSB1I24GNuda5+R8LM=; b=A5rsmi+HwB4Bkn25+5VDrN1sa3Y3Nb9EP8hQ5ZlsGN8WjwIcHC0LUJRDFAqEwV+DJB p4kSfgAqp2biA6Rt1fKLdXfcxoCPKqINjlATB7gIoBieNLieI+4GLchk51qYzJvKcN0i 7qTYT0oQ32cct3ifXUkfSLMi9Dv3J6ISFJWzO4TpqCEcRSZIcvvsjQzd2vOp542nBzqp 2UzSIYj7JQhjte+AMYP44JeMzByt6XYbGrGEgzReMGbUGbrON1+2XJqMGP4PV1Ak5kUR TZ+sR/py161MbXbnArPpS5Sx7fpdOem8hECmFknkrV+MCGWZHmNbMb7oW8EX4erNOazh FFYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689755590; x=1692347590; 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=5RXWxXthawWjmUY9dkdjn2rnAJSB1I24GNuda5+R8LM=; b=MEfnF/gxLPAESD58esJ4lO43y0Z7LkveeHlRygYXomkNMKV/nYnj2fcLwIAwUeKsRc jG8BkCY3Ab80I6oML1gzvGwaz33JomB8HVSW3aaGGMfx8JTzUu/dxeWGWaQFk2ZXZsbU 9AB8LcqP1ZGtaS7Y4bjHlehh/hWX2iqWtOKQ4KAeuCYZI51qKTCmXLIxD4SFN6D6X8bH MzN1SSr2aMY7ky/rHgGaRmDn+JWkoDem3YW5UYgpI9hmg0xQc9jHMW+Ektxmcjoc4Vi9 VO6XOerm8urRwnDUnGmV1mJLoLkxCHG2JzLfHmi4uCqlasrZ0U340cJu+sG1ox3d2y95 zLIQ== X-Gm-Message-State: ABy/qLYpNOIUM9UacaMhNQbOTS/1FqeQemqWDPNPRDujUB2kIGuX4bxL 71zZTD5cFvHuIAtXqPwWQCBgaDEpfCPxD2E/P9b00VyU X-Google-Smtp-Source: APBJJlFq7yg0NDfYuFp7fKNwVPjG1mguHGeVAAOOB8vN+o4d+TAeeIh3aKWHQX2nseZU2KlEp6l/Tqkr2kSQOCsNPl8= X-Received: by 2002:a2e:3a14:0:b0:2b6:e618:b597 with SMTP id h20-20020a2e3a14000000b002b6e618b597mr16811653lja.28.1689755589995; Wed, 19 Jul 2023 01:33:09 -0700 (PDT) MIME-Version: 1.0 References: <20230715031957.1147225-1-apinski@marvell.com> In-Reply-To: <20230715031957.1147225-1-apinski@marvell.com> From: Richard Biener Date: Wed, 19 Jul 2023 10:32:37 +0200 Message-ID: Subject: Re: [PATCH 1/2] Add flow_sensitive_info_storage and use it in gimple-fold. 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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,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 Sat, Jul 15, 2023 at 5:21=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > This adds flow_sensitive_info_storage and uses it in > maybe_fold_comparisons_from_match_pd as mentioned in > https://gcc.gnu.org/pipermail/gcc-patches/2023-June/621817.html . > Since using it in maybe_fold_comparisons_from_match_pd was easy > and allowed me to test the storage earlier, I did it. > > This also hides better how the flow sensitive information is > stored and only a single place needs to be updated if that > ever changes (again). > > OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. OK. Thanks for doing this! Richard. > gcc/ChangeLog: > > * gimple-fold.cc (fosa_unwind): Replace `vrange_storage *` > with flow_sensitive_info_storage. > (follow_outer_ssa_edges): Update how to save off the flow > sensitive info. > (maybe_fold_comparisons_from_match_pd): Update restoring > of flow sensitive info. > * tree-ssanames.cc (flow_sensitive_info_storage::save): New metho= d. > (flow_sensitive_info_storage::restore): New method. > (flow_sensitive_info_storage::save_and_clear): New method. > (flow_sensitive_info_storage::clear_storage): New method. > * tree-ssanames.h (class flow_sensitive_info_storage): New class. > --- > gcc/gimple-fold.cc | 17 +++++------ > gcc/tree-ssanames.cc | 72 ++++++++++++++++++++++++++++++++++++++++++++ > gcc/tree-ssanames.h | 21 +++++++++++++ > 3 files changed, 100 insertions(+), 10 deletions(-) > > diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc > index 4027ff71e10..de94efbcff7 100644 > --- a/gcc/gimple-fold.cc > +++ b/gcc/gimple-fold.cc > @@ -6947,7 +6947,7 @@ and_comparisons_1 (tree type, enum tree_code code1,= tree op1a, tree op1b, > } > > static basic_block fosa_bb; > -static vec > *fosa_unwind; > +static vec > *fosa_unwind; > static tree > follow_outer_ssa_edges (tree val) > { > @@ -6967,14 +6967,11 @@ follow_outer_ssa_edges (tree val) > || POINTER_TYPE_P (TREE_TYPE (val))) > && !TYPE_OVERFLOW_WRAPS (TREE_TYPE (val))) > return NULL_TREE; > + flow_sensitive_info_storage storage; > + storage.save_and_clear (val); > /* If the definition does not dominate fosa_bb temporarily reset > flow-sensitive info. */ > - if (val->ssa_name.info.range_info) > - { > - fosa_unwind->safe_push (std::make_pair > - (val, val->ssa_name.info.range_info))= ; > - val->ssa_name.info.range_info =3D NULL; > - } > + fosa_unwind->safe_push (std::make_pair (val, storage)); > return val; > } > return val; > @@ -7034,14 +7031,14 @@ maybe_fold_comparisons_from_match_pd (tree type, = enum tree_code code, > type, gimple_assign_lhs (stmt1), > gimple_assign_lhs (stmt2)); > fosa_bb =3D outer_cond_bb; > - auto_vec, 8> unwind_stack; > + auto_vec, 8> unwind_stack= ; > fosa_unwind =3D &unwind_stack; > if (op.resimplify (NULL, (!outer_cond_bb > ? follow_all_ssa_edges : follow_outer_ssa_edg= es))) > { > fosa_unwind =3D NULL; > for (auto p : unwind_stack) > - p.first->ssa_name.info.range_info =3D p.second; > + p.second.restore (p.first); > if (gimple_simplified_result_is_gimple_val (&op)) > { > tree res =3D op.ops[0]; > @@ -7065,7 +7062,7 @@ maybe_fold_comparisons_from_match_pd (tree type, en= um tree_code code, > } > fosa_unwind =3D NULL; > for (auto p : unwind_stack) > - p.first->ssa_name.info.range_info =3D p.second; > + p.second.restore (p.first); > > return NULL_TREE; > } > diff --git a/gcc/tree-ssanames.cc b/gcc/tree-ssanames.cc > index 5fdb6a37e9f..f81332451fc 100644 > --- a/gcc/tree-ssanames.cc > +++ b/gcc/tree-ssanames.cc > @@ -916,3 +916,75 @@ make_pass_release_ssa_names (gcc::context *ctxt) > { > return new pass_release_ssa_names (ctxt); > } > + > +/* Save and restore of flow sensitive information. */ > + > +/* Save off the flow sensitive info from NAME. */ > + > +void > +flow_sensitive_info_storage::save (tree name) > +{ > + gcc_assert (state =3D=3D 0); > + if (!POINTER_TYPE_P (TREE_TYPE (name))) > + { > + range_info =3D SSA_NAME_RANGE_INFO (name); > + state =3D 1; > + return; > + } > + state =3D -1; > + auto ptr_info =3D SSA_NAME_PTR_INFO (name); > + if (ptr_info) > + { > + align =3D ptr_info->align; > + misalign =3D ptr_info->misalign; > + null =3D SSA_NAME_PTR_INFO (name)->pt.null; > + } > + else > + { > + align =3D 0; > + misalign =3D 0; > + null =3D true; > + } > +} > + > +/* Restore the flow sensitive info from NAME. */ > + > +void > +flow_sensitive_info_storage::restore (tree name) > +{ > + gcc_assert (state !=3D 0); > + if (!POINTER_TYPE_P (TREE_TYPE (name))) > + { > + gcc_assert (state =3D=3D 1); > + SSA_NAME_RANGE_INFO (name) =3D range_info; > + return; > + } > + gcc_assert (state =3D=3D -1); > + auto ptr_info =3D SSA_NAME_PTR_INFO (name); > + /* If there was no flow sensitive info on the pointer > + just return, there is nothing to restore to. */ > + if (!ptr_info) > + return; > + if (align !=3D 0) > + set_ptr_info_alignment (ptr_info, align, misalign); > + else > + mark_ptr_info_alignment_unknown (ptr_info); > + SSA_NAME_PTR_INFO (name)->pt.null =3D null; > +} > + > +/* Save off the flow sensitive info from NAME. > + And reset the flow sensitive info of NAME. */ > + > +void > +flow_sensitive_info_storage::save_and_clear (tree name) > +{ > + save (name); > + reset_flow_sensitive_info (name); > +} > + > +/* Clear the storage. */ > +void > +flow_sensitive_info_storage::clear_storage (void) > +{ > + state =3D 0; > +} > diff --git a/gcc/tree-ssanames.h b/gcc/tree-ssanames.h > index f3fa609208a..98f4a835483 100644 > --- a/gcc/tree-ssanames.h > +++ b/gcc/tree-ssanames.h > @@ -136,5 +136,26 @@ make_temp_ssa_name (tree type, gimple *stmt, const c= har *name) > return ssa_name; > } > > +/* A class which is used to save/restore the flow sensitive information.= */ > +class flow_sensitive_info_storage > +{ > +public: > + void save (tree); > + void save_and_clear (tree); > + void restore (tree); > + void clear_storage (); > +private: > + /* 0 means there is nothing saved. > + 1 means non pointer is saved. > + -1 means a pointer type is saved. > + -2 means a pointer type is saved but no information was saved. */ > + int state =3D 0; > + /* The range info for non pointers */ > + vrange_storage *range_info =3D nullptr; > + /* Flow sensitive pointer information. */ > + unsigned int align =3D 0; > + unsigned int misalign =3D 0; > + bool null =3D true; > +}; > > #endif /* GCC_TREE_SSANAMES_H */ > -- > 2.31.1 >