public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Avoid TYPE_MAIN_VARIANT compares in TBAA
@ 2024-05-14 10:57 Jan Hubicka
  2024-05-14 12:29 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2024-05-14 10:57 UTC (permalink / raw)
  To: gcc-patches, rguenther

Hi,
while building more testcases for ipa-icf I noticed that there are two places
in aliasing code where we still compare TYPE_MAIN_VARIANT for pointer equality.
This is not good idea for LTO since type merging may not happen for example
when in one unit pointed to type is forward declared while in other it is fully
defined.  We have same_type_for_tbaa for that.

Bootstrapped/regtested x86_64-linux, OK?

gcc/ChangeLog:

	* alias.cc (reference_alias_ptr_type_1): Use view_converted_memref_p.
	* alias.h (view_converted_memref_p): Declare.
	* tree-ssa-alias.cc (view_converted_memref_p): Export.
	(ao_compare::compare_ao_refs): Use same_type_for_tbaa.

diff --git a/gcc/alias.cc b/gcc/alias.cc
index 808e2095d9b..853e84d7439 100644
--- a/gcc/alias.cc
+++ b/gcc/alias.cc
@@ -770,10 +770,7 @@ reference_alias_ptr_type_1 (tree *t)
   /* If the innermost reference is a MEM_REF that has a
      conversion embedded treat it like a VIEW_CONVERT_EXPR above,
      using the memory access type for determining the alias-set.  */
-  if (TREE_CODE (inner) == MEM_REF
-      && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
-	  != TYPE_MAIN_VARIANT
-	       (TREE_TYPE (TREE_TYPE (TREE_OPERAND (inner, 1))))))
+  if (view_converted_memref_p (inner))
     {
       tree alias_ptrtype = TREE_TYPE (TREE_OPERAND (inner, 1));
       /* Unless we have the (aggregate) effective type of the access
diff --git a/gcc/alias.h b/gcc/alias.h
index f8d93e8b5f4..36095f0bf73 100644
--- a/gcc/alias.h
+++ b/gcc/alias.h
@@ -41,6 +41,7 @@ bool alias_ptr_types_compatible_p (tree, tree);
 int compare_base_decls (tree, tree);
 bool refs_same_for_tbaa_p (tree, tree);
 bool mems_same_for_tbaa_p (rtx, rtx);
+bool view_converted_memref_p (tree);
 
 /* This alias set can be used to force a memory to conflict with all
    other memories, creating a barrier across which no memory reference
diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index e7c1c1aa624..632cf78028b 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2044,7 +2044,7 @@ decl_refs_may_alias_p (tree ref1, tree base1,
    which is done by ao_ref_base and thus one extra walk
    of handled components is needed.  */
 
-static bool
+bool
 view_converted_memref_p (tree base)
 {
   if (TREE_CODE (base) != MEM_REF && TREE_CODE (base) != TARGET_MEM_REF)
@@ -4325,8 +4325,8 @@ ao_compare::compare_ao_refs (ao_ref *ref1, ao_ref *ref2,
   else if ((end_struct_ref1 != NULL) != (end_struct_ref2 != NULL))
     return flags | ACCESS_PATH;
   if (end_struct_ref1
-      && TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref1))
-	 != TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref2)))
+      && same_type_for_tbaa (TREE_TYPE (end_struct_ref1),
+			     TREE_TYPE (end_struct_ref2)) != 1)
     return flags | ACCESS_PATH;
 
   /* Now compare all handled components of the access path.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Avoid TYPE_MAIN_VARIANT compares in TBAA
  2024-05-14 10:57 Avoid TYPE_MAIN_VARIANT compares in TBAA Jan Hubicka
@ 2024-05-14 12:29 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2024-05-14 12:29 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On Tue, 14 May 2024, Jan Hubicka wrote:

> Hi,
> while building more testcases for ipa-icf I noticed that there are two places
> in aliasing code where we still compare TYPE_MAIN_VARIANT for pointer equality.
> This is not good idea for LTO since type merging may not happen for example
> when in one unit pointed to type is forward declared while in other it is fully
> defined.  We have same_type_for_tbaa for that.
> 
> Bootstrapped/regtested x86_64-linux, OK?

OK.

Richard.

> gcc/ChangeLog:
> 
> 	* alias.cc (reference_alias_ptr_type_1): Use view_converted_memref_p.
> 	* alias.h (view_converted_memref_p): Declare.
> 	* tree-ssa-alias.cc (view_converted_memref_p): Export.
> 	(ao_compare::compare_ao_refs): Use same_type_for_tbaa.
> 
> diff --git a/gcc/alias.cc b/gcc/alias.cc
> index 808e2095d9b..853e84d7439 100644
> --- a/gcc/alias.cc
> +++ b/gcc/alias.cc
> @@ -770,10 +770,7 @@ reference_alias_ptr_type_1 (tree *t)
>    /* If the innermost reference is a MEM_REF that has a
>       conversion embedded treat it like a VIEW_CONVERT_EXPR above,
>       using the memory access type for determining the alias-set.  */
> -  if (TREE_CODE (inner) == MEM_REF
> -      && (TYPE_MAIN_VARIANT (TREE_TYPE (inner))
> -	  != TYPE_MAIN_VARIANT
> -	       (TREE_TYPE (TREE_TYPE (TREE_OPERAND (inner, 1))))))
> +  if (view_converted_memref_p (inner))
>      {
>        tree alias_ptrtype = TREE_TYPE (TREE_OPERAND (inner, 1));
>        /* Unless we have the (aggregate) effective type of the access
> diff --git a/gcc/alias.h b/gcc/alias.h
> index f8d93e8b5f4..36095f0bf73 100644
> --- a/gcc/alias.h
> +++ b/gcc/alias.h
> @@ -41,6 +41,7 @@ bool alias_ptr_types_compatible_p (tree, tree);
>  int compare_base_decls (tree, tree);
>  bool refs_same_for_tbaa_p (tree, tree);
>  bool mems_same_for_tbaa_p (rtx, rtx);
> +bool view_converted_memref_p (tree);
>  
>  /* This alias set can be used to force a memory to conflict with all
>     other memories, creating a barrier across which no memory reference
> diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
> index e7c1c1aa624..632cf78028b 100644
> --- a/gcc/tree-ssa-alias.cc
> +++ b/gcc/tree-ssa-alias.cc
> @@ -2044,7 +2044,7 @@ decl_refs_may_alias_p (tree ref1, tree base1,
>     which is done by ao_ref_base and thus one extra walk
>     of handled components is needed.  */
>  
> -static bool
> +bool
>  view_converted_memref_p (tree base)
>  {
>    if (TREE_CODE (base) != MEM_REF && TREE_CODE (base) != TARGET_MEM_REF)
> @@ -4325,8 +4325,8 @@ ao_compare::compare_ao_refs (ao_ref *ref1, ao_ref *ref2,
>    else if ((end_struct_ref1 != NULL) != (end_struct_ref2 != NULL))
>      return flags | ACCESS_PATH;
>    if (end_struct_ref1
> -      && TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref1))
> -	 != TYPE_MAIN_VARIANT (TREE_TYPE (end_struct_ref2)))
> +      && same_type_for_tbaa (TREE_TYPE (end_struct_ref1),
> +			     TREE_TYPE (end_struct_ref2)) != 1)
>      return flags | ACCESS_PATH;
>  
>    /* Now compare all handled components of the access path.
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH,
Frankenstrasse 146, 90461 Nuernberg, Germany;
GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-14 12:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14 10:57 Avoid TYPE_MAIN_VARIANT compares in TBAA Jan Hubicka
2024-05-14 12:29 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).