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 46ACE3858D1E for ; Mon, 6 May 2024 07:27:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46ACE3858D1E 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 46ACE3858D1E 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=1714980479; cv=none; b=YhtrEnvxypaPQx9NbwFZjeQbl/nYDt1hI+hmD0a9abh0DjJx+G+b41NG+O/ZCtpZAlu6oqOVa/DJD4+4Qb3dY9CT2Gu5pgrbxlEVBs96bcGN7S39nObJKia8ogwxwGuE9tFnG6Px04/ffjew2cLNCouIS5ODKRFDo5uF4wFhRJE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714980479; c=relaxed/simple; bh=nG6MFVFxfHO0S8Fk6Rd/oaayuvHrYMpKiqqkzcVYDgs=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=ec2muXghQu3sWtcxbgJoXfccbtV5jyYamllh8jbVEe0pbNR5ZQkizwL3SoNqwK0R1N0pkmUjJEkrlPccf0AyiC1X9o36QNBQeJ9Pm/BQNSw6PyrnfE8z/Uw5J8nSxa/gKegzVlACdfILzEdUCQLzhG+Rq4jwG/2sUtTDz3U5LDk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from fbmtpc21.tugraz.at (fbmtpc21.tugraz.at [129.27.144.40]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4VXtKh1swwz3wJl; Mon, 6 May 2024 09:27:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1714980472; bh=/5CBuWh7oz03tlh5J4j8a3ikBhn63Pz/PnLUKcr9PaM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=pL489HJh+xbLvIJelCa1Fhj9yT2AimZx5dO3LmaQPi8sk3v6EUS55NYkfVsMNflhR uhSMPqcbXzRgNQeLvOgtcUYIWKF9e+gfq06sa1yKuRmg6bXKn0FQm1Of+SKehjN6/P AZPdZyP0zsNzGrA5DRLwCHq4u0q6SPNP/juFAlhg= Message-ID: <716c2beda1d6f9876612d42902cc8a21c593ed2a.camel@tugraz.at> Subject: Re: [PATCH] middle-end/114931 - type_hash_canon and structual equality types From: Martin Uecker To: Richard Biener Cc: Jakub Jelinek , gcc-patches@gcc.gnu.org, Jan Hubicka Date: Mon, 06 May 2024 09:27:52 +0200 In-Reply-To: <3s4pqo5q-qron-7899-p7q4-rpr81n2q0p90@fhfr.qr> References: <05B84303-9D17-4DAE-A9D9-A77DA3EA7878@suse.de> <39fcac8a1c61acaaa1c80602b76f48ef73f5f885.camel@tugraz.at> <3s4pqo5q-qron-7899-p7q4-rpr81n2q0p90@fhfr.qr> 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=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Montag, dem 06.05.2024 um 09:00 +0200 schrieb Richard Biener: > On Sat, 4 May 2024, Martin Uecker wrote: >=20 > > Am Freitag, dem 03.05.2024 um 21:16 +0200 schrieb Jakub Jelinek: > > > > On Fri, May 03, 2024 at 09:11:20PM +0200, Martin Uecker wrote: > > > > > > > > TYPE_CANONICAL as used by the middle-end cannot express thi= s but > > > > > >=20 > > > > > > Hm. so how does it work now for arrays? > > > >=20 > > > > Do you have a testcase which doesn't work correctly with the arrays= ? > >=20 > > I am mostly trying to understand better how this works. But > > if I am not mistaken, the following example would indeed > > indicate that we do incorrect aliasing decisions for types > > derived from arrays: > >=20 > > https://godbolt.org/z/rTsE3PhKc >=20 > This example is about pointer-to-array types, int (*)[2] and > int (*)[1] are supposed to be compatible as in receive the same alias > set.=C2=A0 In C, char (*)[2] and char (*)[1] are not compatible. But with COMPAT set, the example operates^1 with char (*)[] and char (*)[1] which are compatible. If we form equivalence classes, then all three types would need to be treated as equivalent.=20 ^1 Actually, pointer to functions returning pointers to arrays. Probably this example can still be simplified... > This is ensured by get_alias_set POINTER_TYPE_P handling, > the alias set is supposed to be the same as that of int *. It seems > we do restrict the handling a bit, the code does >=20 > /* Unnest all pointers and references. > We also want to make pointer to array/vector equivalent to=20 > pointer to > its element (see the reasoning above). Skip all those types, too= . =20 > */ > for (p =3D t; POINTER_TYPE_P (p) > || (TREE_CODE (p) =3D=3D ARRAY_TYPE > && (!TYPE_NONALIASED_COMPONENT (p) > || !COMPLETE_TYPE_P (p) > || TYPE_STRUCTURAL_EQUALITY_P (p))) > || TREE_CODE (p) =3D=3D VECTOR_TYPE; > p =3D TREE_TYPE (p)) >=20 > where the comment doesn't exactly match the code - but C should > never have TYPE_NONALIASED_COMPONENT (p). >=20 > But maybe I misread the example or it goes wrong elsewhere. If I am not confusing myself too much, the example shows that aliasing analysis treats the the types as incompatible in both cases, because it does not reload *a with -O2.=20 For char (*)[1] and char (*)[2] this would be correct (but an implementation exploiting this would need to do structural comparisons and not equivalence classes) but for=C2=A0 char (*)[2] and char (*)[] it is not. Martin >=20 > Richard. >=20 > > Martin > >=20 > > > >=20 > > > > E.g. same_type_for_tbaa has > > > > type1 =3D TYPE_MAIN_VARIANT (type1); > > > > type2 =3D TYPE_MAIN_VARIANT (type2); > > > >=20 > > > > /* Handle the most common case first. */ > > > > if (type1 =3D=3D type2) > > > > return 1; > > > >=20 > > > > /* If we would have to do structural comparison bail out. */ > > > > if (TYPE_STRUCTURAL_EQUALITY_P (type1) > > > > || TYPE_STRUCTURAL_EQUALITY_P (type2)) > > > > return -1; > > > >=20 > > > > /* Compare the canonical types. */ > > > > if (TYPE_CANONICAL (type1) =3D=3D TYPE_CANONICAL (type2)) > > > > return 1; > > > >=20 > > > > /* ??? Array types are not properly unified in all cases as we ha= ve > > > > spurious changes in the index types for example. Removing thi= s > > > > causes all sorts of problems with the Fortran frontend. */ > > > > if (TREE_CODE (type1) =3D=3D ARRAY_TYPE > > > > && TREE_CODE (type2) =3D=3D ARRAY_TYPE) > > > > return -1; > > > > ... > > > > and later compares alias sets and the like. > > > > So, even if int[] and int[0] have different TYPE_CANONICAL, they > > > > will be considered maybe the same. Also, guess get_alias_set > > > > has some ARRAY_TYPE handling... > > > >=20 > > > > Anyway, I think we should just go with Richi's patch. > > > >=20 > > > > Jakub > > > >=20 > >=20 > >=20 > >=20 >=20 --=20 Univ.-Prof. Dr. rer. nat. Martin Uecker Graz University of Technology Institute of Biomedical Imaging