From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id AD03B384AB58 for ; Fri, 3 May 2024 17:44:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD03B384AB58 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD03B384AB58 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=129.27.2.202 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714758248; cv=none; b=D3wP19gw0zPZwa4mkC9zOVnWmG5BvDt5RxGRSyygycm9fW3itcO+rwHZKCNgH4nmG4jxz9vrZae3U4ZVg45RUOl7KOutsNMyLYlcgsvCtlNXpdkYvUJ60LjyzyszASL47+lIutOaHn/67Ihoqi9/ogdoSnf5Z7KNUFmTQHoRxmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714758248; c=relaxed/simple; bh=xjWr9MmM4d2jE+OVOYHfgRbCYtEaXbYzC1AN5dcSmHQ=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=Q/rLocSzw4vqUFrYgjFsFoLgLO+BWNO+zA/m9y5cg6AHghna7Jc0R6DJT8ZCTAzYwkvVZC1bdjdIB9l6k3f8NgjvwY6YWLEKBgsI83huNvuzYX9jqwjpy4C1vGP5agORLxj37nhbHV9le3J7CSGjAeyvqYDZR7RIVTaigx1pCjI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [192.168.0.221] (84-115-223-216.cable.dynamic.surfer.at [84.115.223.216]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4VWJ811D8lz1LM0V; Fri, 3 May 2024 19:44:01 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4VWJ811D8lz1LM0V DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1714758241; bh=V0W+jxHswcHyAjx3sQZhNQtCsDzQG3Do5o84W00t0gU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=tr04/8m86QuOpNZfnZvmvjgcdTK05G58U0Bw1aFoAfWAuv66kD5oQGbko8nxqDM7j h7imeHu4JV9R+XiCI76+jfX1m3zQobtO/We1P6+qBlOUZI0MRCX6CiK9B4fzve5Y3g 5kWl9cn/p2Fw7ykZyTYvIYAuKGRUMrY3gMA7x6EA= Message-ID: <034f192d70d2c8f83ee5bee5e6db9e0ac42b5895.camel@tugraz.at> Subject: Re: [PATCH] middle-end/114931 - type_hash_canon and structual equality types From: Martin Uecker To: Richard Biener Cc: gcc-patches@gcc.gnu.org, Jakub Jelinek Date: Fri, 03 May 2024 19:44:00 +0200 In-Reply-To: <0D3EFE04-0E5E-4373-AECE-6B5CC6AA6379@suse.de> References: <3616afcc455c1f80e2bb8a80a408994a67062d85.camel@tugraz.at> <0D3EFE04-0E5E-4373-AECE-6B5CC6AA6379@suse.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-8.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_ABUSEAT,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP 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: Am Freitag, dem 03.05.2024 um 18:23 +0200 schrieb Richard Biener: >=20 > > Am 03.05.2024 um 17:33 schrieb Martin Uecker : > >=20 > > =EF=BB=BFAm Freitag, dem 03.05.2024 um 14:13 +0200 schrieb Richard Bien= er: > > > TYPE_STRUCTURAL_EQUALITY_P is part of our type system so we have > > > to make sure to include that into the type unification done via > > > type_hash_canon. This requires the flag to be set before querying > > > the hash which is the biggest part of the patch. > >=20 > > I assume this does not affect structs / unions because they > > do not make this mechanism of type unification (each tagged type > > is a unique type), but only derived types that end up having > > TYPE_STRUCTURAL_EQUALITY_P because they are constructed from > > incomplete structs / unions before TYPE_CANONICAL is set. > >=20 > > I do not yet understand why this change is needed. Type > > identity should not be affected by setting TYPE_CANONICAL, so > > why do we need to keep such types separate? I understand that we > > created some inconsistencies, but I do not see why this change > > is needed to fix it. But I also haven't understood how we ended > > up with a TYPE_CANONICAL having TYPE_STRUCTURAL_EQUALITY_P in > > PR 114931 ... >=20 > Because we created the canonical function type before where one > of its arguments had TYPE_STEUCTURAL_EQUALITY which makes the > function type so. So build_function_type when called recursively for creating a TYPE_CANONICAL found some type with TYPE_STRUCTURAL_EQUALITY. And the plan is to separate those in the hash table so that this cannot happen? Couldn't we instead lazily update TYPE_CANONICAL at this point?=20 Martin >=20 > Richard=20 >=20 > >=20 > > Martin > >=20 > >=20 > > >=20 > > > Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages= . > > >=20 > > > As said in the PR this merely makes sure to keep individual types > > > consistent with themselves. We still will have a set of types > > > with TYPE_STRUCTURAL_EQUALITY_P and a set without that might be > > > otherwise identical. That could be only avoided with changes in > > > the frontend. > > >=20 > > > OK for trunk? > > >=20 > > > Thanks, > > > Richard. > > >=20 > > > PR middle-end/114931 > > > gcc/ > > > * tree.cc (type_hash_canon_hash): Hash TYPE_STRUCTURAL_EQUALITY_P. > > > (type_cache_hasher::equal): Compare TYPE_STRUCTURAL_EQUALITY_P. > > > (build_array_type_1): Set TYPE_STRUCTURAL_EQUALITY_P before > > > probing with type_hash_canon. > > > (build_function_type): Likewise. > > > (build_method_type_directly): Likewise. > > > (build_offset_type): Likewise. > > > (build_complex_type): Likewise. > > > * attribs.cc (build_type_attribute_qual_variant): Likewise. > > >=20 > > > gcc/c-family/ > > > * c-common.cc (complete_array_type): Set TYPE_STRUCTURAL_EQUALITY_= P > > > before probing with type_hash_canon. > > >=20 > > > gcc/testsuite/ > > > * gcc.dg/pr114931.c: New testcase. > > > --- > > > gcc/attribs.cc | 20 +++++----- > > > gcc/c-family/c-common.cc | 11 ++++-- > > > gcc/testsuite/gcc.dg/pr114931.c | 10 +++++ > > > gcc/tree.cc | 65 +++++++++++++++++++++++---------= - > > > 4 files changed, 74 insertions(+), 32 deletions(-) > > > create mode 100644 gcc/testsuite/gcc.dg/pr114931.c > > >=20 > > > diff --git a/gcc/attribs.cc b/gcc/attribs.cc > > > index 12ffc5f170a..3ab0b0fd87a 100644 > > > --- a/gcc/attribs.cc > > > +++ b/gcc/attribs.cc > > > @@ -1336,6 +1336,16 @@ build_type_attribute_qual_variant (tree otype,= tree attribute, int quals) > > > tree dtype =3D ntype =3D build_distinct_type_copy (ttype); > > >=20 > > > TYPE_ATTRIBUTES (ntype) =3D attribute; > > > + /* If the target-dependent attributes make NTYPE different fro= m > > > + its canonical type, we will need to use structural equality > > > + checks for this type. > > > + > > > + We shouldn't get here for stripping attributes from a type; > > > + the no-attribute type might not need structural comparison. Bu= t > > > + we can if was discarded from type_hash_table. */ > > > + if (TYPE_STRUCTURAL_EQUALITY_P (ttype) > > > + || !comp_type_attributes (ntype, ttype)) > > > + SET_TYPE_STRUCTURAL_EQUALITY (ntype); > > >=20 > > > hashval_t hash =3D type_hash_canon_hash (ntype); > > > ntype =3D type_hash_canon (hash, ntype); > > > @@ -1343,16 +1353,6 @@ build_type_attribute_qual_variant (tree otype,= tree attribute, int quals) > > > if (ntype !=3D dtype) > > > /* This variant was already in the hash table, don't mess with > > > TYPE_CANONICAL. */; > > > - else if (TYPE_STRUCTURAL_EQUALITY_P (ttype) > > > - || !comp_type_attributes (ntype, ttype)) > > > - /* If the target-dependent attributes make NTYPE different from > > > - its canonical type, we will need to use structural equality > > > - checks for this type. > > > - > > > - We shouldn't get here for stripping attributes from a type; > > > - the no-attribute type might not need structural comparison. = But > > > - we can if was discarded from type_hash_table. */ > > > - SET_TYPE_STRUCTURAL_EQUALITY (ntype); > > > else if (TYPE_CANONICAL (ntype) =3D=3D ntype) > > > TYPE_CANONICAL (ntype) =3D TYPE_CANONICAL (ttype); > > >=20 > > > diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc > > > index 01e3d247fc2..032dcb4b41d 100644 > > > --- a/gcc/c-family/c-common.cc > > > +++ b/gcc/c-family/c-common.cc > > > @@ -7115,6 +7115,13 @@ complete_array_type (tree *ptype, tree initial= _value, bool do_default) > > > TYPE_TYPELESS_STORAGE (main_type) =3D TYPE_TYPELESS_STORAGE (type); > > > layout_type (main_type); > > >=20 > > > + /* Set TYPE_STRUCTURAL_EQUALITY_P early. */ > > > + if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type)) > > > + || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type))) > > > + SET_TYPE_STRUCTURAL_EQUALITY (main_type); > > > + else > > > + TYPE_CANONICAL (main_type) =3D main_type; > > > + > > > /* Make sure we have the canonical MAIN_TYPE. */ > > > hashval_t hashcode =3D type_hash_canon_hash (main_type); > > > main_type =3D type_hash_canon (hashcode, main_type); > > > @@ -7122,7 +7129,7 @@ complete_array_type (tree *ptype, tree initial_= value, bool do_default) > > > /* Fix the canonical type. */ > > > if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (main_type)) > > > || TYPE_STRUCTURAL_EQUALITY_P (TYPE_DOMAIN (main_type))) > > > - SET_TYPE_STRUCTURAL_EQUALITY (main_type); > > > + gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (main_type)); > > > else if (TYPE_CANONICAL (TREE_TYPE (main_type)) !=3D TREE_TYPE (mai= n_type) > > > || (TYPE_CANONICAL (TYPE_DOMAIN (main_type)) > > > !=3D TYPE_DOMAIN (main_type))) > > > @@ -7130,8 +7137,6 @@ complete_array_type (tree *ptype, tree initial_= value, bool do_default) > > > =3D build_array_type (TYPE_CANONICAL (TREE_TYPE (main_type)), > > > TYPE_CANONICAL (TYPE_DOMAIN (main_type)), > > > TYPE_TYPELESS_STORAGE (main_type)); > > > - else > > > - TYPE_CANONICAL (main_type) =3D main_type; > > >=20 > > > if (quals =3D=3D 0) > > > type =3D main_type; > > > diff --git a/gcc/testsuite/gcc.dg/pr114931.c b/gcc/testsuite/gcc.dg/p= r114931.c > > > new file mode 100644 > > > index 00000000000..d690ed70e52 > > > --- /dev/null > > > +++ b/gcc/testsuite/gcc.dg/pr114931.c > > > @@ -0,0 +1,10 @@ > > > +/* { dg-do compile } */ > > > +/* { dg-options "-std=3Dc23" } */ > > > + > > > +struct Tcl_Obj; > > > +void(Tcl_FreeInternalRepProc)(struct Tcl_Obj *); > > > +typedef struct Tcl_Obj { > > > +} Tcl_Obj; > > > +struct { > > > + void (*tclFreeObj)(Tcl_Obj *); > > > +} Tcl_InitStubs; > > > diff --git a/gcc/tree.cc b/gcc/tree.cc > > > index 780662549fe..6564b002dc1 100644 > > > --- a/gcc/tree.cc > > > +++ b/gcc/tree.cc > > > @@ -6012,6 +6012,8 @@ type_hash_canon_hash (tree type) > > >=20 > > > hstate.add_int (TREE_CODE (type)); > > >=20 > > > + hstate.add_flag (TYPE_STRUCTURAL_EQUALITY_P (type)); > > > + > > > if (TREE_TYPE (type)) > > > hstate.add_object (TYPE_HASH (TREE_TYPE (type))); > > >=20 > > > @@ -6109,6 +6111,10 @@ type_cache_hasher::equal (type_hash *a, type_h= ash *b) > > > || TYPE_MODE (a->type) !=3D TYPE_MODE (b->type))) > > > return false; > > >=20 > > > + if (TYPE_STRUCTURAL_EQUALITY_P (a->type) > > > + !=3D TYPE_STRUCTURAL_EQUALITY_P (b->type)) > > > + return false; > > > + > > > switch (TREE_CODE (a->type)) > > > { > > > case VOID_TYPE: > > > @@ -7347,6 +7353,14 @@ build_array_type_1 (tree elt_type, tree index_= type, bool typeless_storage, > > > TYPE_DOMAIN (t) =3D index_type; > > > TYPE_ADDR_SPACE (t) =3D TYPE_ADDR_SPACE (elt_type); > > > TYPE_TYPELESS_STORAGE (t) =3D typeless_storage; > > > + > > > + /* Set TYPE_STRUCTURAL_EQUALITY_P. */ > > > + if (set_canonical > > > + && (TYPE_STRUCTURAL_EQUALITY_P (elt_type) > > > + || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) > > > + || in_lto_p)) > > > + SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + > > > layout_type (t); > > >=20 > > > if (shared) > > > @@ -7363,7 +7377,7 @@ build_array_type_1 (tree elt_type, tree index_t= ype, bool typeless_storage, > > > if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) > > > || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) > > > || in_lto_p) > > > - SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + gcc_unreachable (); > > > else if (TYPE_CANONICAL (elt_type) !=3D elt_type > > > || (index_type && TYPE_CANONICAL (index_type) !=3D index_ty= pe)) > > > TYPE_CANONICAL (t) > > > @@ -7510,21 +7524,25 @@ build_function_type (tree value_type, tree ar= g_types, > > > TYPE_NO_NAMED_ARGS_STDARG_P (t) =3D 1; > > > } > > >=20 > > > - /* If we already have such a type, use the old one. */ > > > - hashval_t hash =3D type_hash_canon_hash (t); > > > - tree probe_type =3D t; > > > - t =3D type_hash_canon (hash, t); > > > - if (t !=3D probe_type) > > > - return t; > > > - > > > /* Set up the canonical type. */ > > > any_structural_p =3D TYPE_STRUCTURAL_EQUALITY_P (value_type); > > > any_noncanonical_p =3D TYPE_CANONICAL (value_type) !=3D value_type; > > > canon_argtypes =3D maybe_canonicalize_argtypes (arg_types, > > > &any_structural_p, > > > &any_noncanonical_p); > > > + /* Set TYPE_STRUCTURAL_EQUALITY_P early. */ > > > if (any_structural_p) > > > SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + > > > + /* If we already have such a type, use the old one. */ > > > + hashval_t hash =3D type_hash_canon_hash (t); > > > + tree probe_type =3D t; > > > + t =3D type_hash_canon (hash, t); > > > + if (t !=3D probe_type) > > > + return t; > > > + > > > + if (any_structural_p) > > > + gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t)); > > > else if (any_noncanonical_p) > > > TYPE_CANONICAL (t) =3D build_function_type (TYPE_CANONICAL (value= _type), > > > canon_argtypes); > > > @@ -7667,13 +7685,6 @@ build_method_type_directly (tree basetype, > > > argtypes =3D tree_cons (NULL_TREE, ptype, argtypes); > > > TYPE_ARG_TYPES (t) =3D argtypes; > > >=20 > > > - /* If we already have such a type, use the old one. */ > > > - hashval_t hash =3D type_hash_canon_hash (t); > > > - tree probe_type =3D t; > > > - t =3D type_hash_canon (hash, t); > > > - if (t !=3D probe_type) > > > - return t; > > > - > > > /* Set up the canonical type. */ > > > any_structural_p > > > =3D (TYPE_STRUCTURAL_EQUALITY_P (basetype) > > > @@ -7684,8 +7695,20 @@ build_method_type_directly (tree basetype, > > > canon_argtypes =3D maybe_canonicalize_argtypes (TREE_CHAIN (argtype= s), > > > &any_structural_p, > > > &any_noncanonical_p); > > > + > > > + /* Set TYPE_STRUCTURAL_EQUALITY_P early. */ > > > if (any_structural_p) > > > SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + > > > + /* If we already have such a type, use the old one. */ > > > + hashval_t hash =3D type_hash_canon_hash (t); > > > + tree probe_type =3D t; > > > + t =3D type_hash_canon (hash, t); > > > + if (t !=3D probe_type) > > > + return t; > > > + > > > + if (any_structural_p) > > > + gcc_assert (TYPE_STRUCTURAL_EQUALITY_P (t)); > > > else if (any_noncanonical_p) > > > TYPE_CANONICAL (t) > > > =3D build_method_type_directly (TYPE_CANONICAL (basetype), > > > @@ -7726,6 +7749,9 @@ build_offset_type (tree basetype, tree type) > > >=20 > > > TYPE_OFFSET_BASETYPE (t) =3D TYPE_MAIN_VARIANT (basetype); > > > TREE_TYPE (t) =3D type; > > > + if (TYPE_STRUCTURAL_EQUALITY_P (basetype) > > > + || TYPE_STRUCTURAL_EQUALITY_P (type)) > > > + SET_TYPE_STRUCTURAL_EQUALITY (t); > > >=20 > > > /* If we already have such a type, use the old one. */ > > > hashval_t hash =3D type_hash_canon_hash (t); > > > @@ -7741,7 +7767,7 @@ build_offset_type (tree basetype, tree type) > > > { > > > if (TYPE_STRUCTURAL_EQUALITY_P (basetype) > > > || TYPE_STRUCTURAL_EQUALITY_P (type)) > > > - SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + gcc_unreachable (); > > > else if (TYPE_CANONICAL (TYPE_MAIN_VARIANT (basetype)) !=3D bas= etype > > > || TYPE_CANONICAL (type) !=3D type) > > > TYPE_CANONICAL (t) > > > @@ -7770,6 +7796,8 @@ build_complex_type (tree component_type, bool n= amed) > > > tree probe =3D make_node (COMPLEX_TYPE); > > >=20 > > > TREE_TYPE (probe) =3D TYPE_MAIN_VARIANT (component_type); > > > + if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (probe))) > > > + SET_TYPE_STRUCTURAL_EQUALITY (probe); > > >=20 > > > /* If we already have such a type, use the old one. */ > > > hashval_t hash =3D type_hash_canon_hash (probe); > > > @@ -7781,11 +7809,10 @@ build_complex_type (tree component_type, bool= named) > > > out the type. We need to check the canonicalization and > > > maybe set the name. */ > > > gcc_checking_assert (COMPLETE_TYPE_P (t) > > > - && !TYPE_NAME (t) > > > - && TYPE_CANONICAL (t) =3D=3D t); > > > + && !TYPE_NAME (t)); > > >=20 > > > if (TYPE_STRUCTURAL_EQUALITY_P (TREE_TYPE (t))) > > > - SET_TYPE_STRUCTURAL_EQUALITY (t); > > > + ; > > > else if (TYPE_CANONICAL (TREE_TYPE (t)) !=3D TREE_TYPE (t)) > > > TYPE_CANONICAL (t) > > > =3D build_complex_type (TYPE_CANONICAL (TREE_TYPE (t)), named); > >=20