diff mbox

[3/4] Simple relaxation of dynamic type change detection routine

Message ID 20110415125645.503701727@virgil.suse.cz
State New
Headers show

Commit Message

Martin Jambor April 15, 2011, 12:56 p.m. UTC
Hi,

in order to speed up astar, I had to persuade the function that
decides whether a statement potentially modifies the dynamic type of
an object by storing a new value to the VMT pointer to consider the
following statement harmless (all types are integers of some sort):

MEM[(i32 *)b2arp_3(D) + 8B] = 0;

I'd like to experiment with this routine a bit more once I have some
other IPA-CP infrastructure in place but at the moment I opted for a
simple solution:  All scalar non-pointer stores are deemed safe.

VMT pointer is a compiler generated field which is a pointer so legal
user code is not able to store stuff there through some fancy type
casts and compiler generated code should have no reason whatsoever to
that either.  Therefore I believe this change is safe and useful.

I have bootstrapped and tested the patch on x886_64-linux.  OK for
trunk?

Thanks,

Martin



2011-04-14  Martin Jambor  <mjambor@suse.cz>

	* ipa-prop.c (stmt_may_be_vtbl_ptr_store): Return false for scalar
	non-pointer assignments.

Comments

Richard Biener April 15, 2011, 3:28 p.m. UTC | #1
On Fri, 15 Apr 2011, Martin Jambor wrote:

> Hi,
> 
> in order to speed up astar, I had to persuade the function that
> decides whether a statement potentially modifies the dynamic type of
> an object by storing a new value to the VMT pointer to consider the
> following statement harmless (all types are integers of some sort):
> 
> MEM[(i32 *)b2arp_3(D) + 8B] = 0;
> 
> I'd like to experiment with this routine a bit more once I have some
> other IPA-CP infrastructure in place but at the moment I opted for a
> simple solution:  All scalar non-pointer stores are deemed safe.
> 
> VMT pointer is a compiler generated field which is a pointer so legal
> user code is not able to store stuff there through some fancy type
> casts and compiler generated code should have no reason whatsoever to
> that either.  Therefore I believe this change is safe and useful.
> 
> I have bootstrapped and tested the patch on x886_64-linux.  OK for
> trunk?

I think this should be only done for -fstrict-aliasing.

Ok with that change.
Richard.

> Thanks,
> 
> Martin
> 
> 
> 
> 2011-04-14  Martin Jambor  <mjambor@suse.cz>
> 
> 	* ipa-prop.c (stmt_may_be_vtbl_ptr_store): Return false for scalar
> 	non-pointer assignments.
> 
> Index: src/gcc/ipa-prop.c
> ===================================================================
> --- src.orig/gcc/ipa-prop.c
> +++ src/gcc/ipa-prop.c
> @@ -405,13 +405,18 @@ stmt_may_be_vtbl_ptr_store (gimple stmt)
>      {
>        tree lhs = gimple_assign_lhs (stmt);
>  
> -      if (TREE_CODE (lhs) == COMPONENT_REF
> -	  && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1))
> -	  && !AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
> +      if (!AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
> +	{
> +	  if (!POINTER_TYPE_P (TREE_TYPE (lhs)))
>  	    return false;
> -      /* In the future we might want to use get_base_ref_and_offset to find
> -	 if there is a field corresponding to the offset and if so, proceed
> -	 almost like if it was a component ref.  */
> +
> +	  if (TREE_CODE (lhs) == COMPONENT_REF
> +	      && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1)))
> +	    return false;
> +	  /* In the future we might want to use get_base_ref_and_offset to find
> +	     if there is a field corresponding to the offset and if so, proceed
> +	     almost like if it was a component ref.  */
> +	}
>      }
>    return true;
>  }
> 
>
Martin Jambor April 18, 2011, 3:44 p.m. UTC | #2
Hi,

On Fri, Apr 15, 2011 at 05:28:49PM +0200, Richard Guenther wrote:
> On Fri, 15 Apr 2011, Martin Jambor wrote:
> 
> > Hi,
> > 
> > in order to speed up astar, I had to persuade the function that
> > decides whether a statement potentially modifies the dynamic type of
> > an object by storing a new value to the VMT pointer to consider the
> > following statement harmless (all types are integers of some sort):
> > 
> > MEM[(i32 *)b2arp_3(D) + 8B] = 0;
> > 
> > I'd like to experiment with this routine a bit more once I have some
> > other IPA-CP infrastructure in place but at the moment I opted for a
> > simple solution:  All scalar non-pointer stores are deemed safe.
> > 
> > VMT pointer is a compiler generated field which is a pointer so legal
> > user code is not able to store stuff there through some fancy type
> > casts and compiler generated code should have no reason whatsoever to
> > that either.  Therefore I believe this change is safe and useful.
> > 
> > I have bootstrapped and tested the patch on x886_64-linux.  OK for
> > trunk?
> 
> I think this should be only done for -fstrict-aliasing.
> 
> Ok with that change.

OK, this is what I am testing and what I intend to commit if all goes
well.

Thanks,

Martin

2011-04-18  Martin Jambor  <mjambor@suse.cz>

	* ipa-prop.c (stmt_may_be_vtbl_ptr_store): Return false for scalar
	non-pointer assignments.

Index: src/gcc/ipa-prop.c
===================================================================
*** src.orig/gcc/ipa-prop.c
--- src/gcc/ipa-prop.c
*************** stmt_may_be_vtbl_ptr_store (gimple stmt)
*** 405,417 ****
      {
        tree lhs = gimple_assign_lhs (stmt);
  
!       if (TREE_CODE (lhs) == COMPONENT_REF
! 	  && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1))
! 	  && !AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
  	    return false;
!       /* In the future we might want to use get_base_ref_and_offset to find
! 	 if there is a field corresponding to the offset and if so, proceed
! 	 almost like if it was a component ref.  */
      }
    return true;
  }
--- 405,423 ----
      {
        tree lhs = gimple_assign_lhs (stmt);
  
!       if (!AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
! 	{
! 	  if (flag_strict_aliasing
! 	      && !POINTER_TYPE_P (TREE_TYPE (lhs)))
  	    return false;
! 
! 	  if (TREE_CODE (lhs) == COMPONENT_REF
! 	      && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1)))
! 	    return false;
! 	  /* In the future we might want to use get_base_ref_and_offset to find
! 	     if there is a field corresponding to the offset and if so, proceed
! 	     almost like if it was a component ref.  */
! 	}
      }
    return true;
  }
diff mbox

Patch

Index: src/gcc/ipa-prop.c
===================================================================
--- src.orig/gcc/ipa-prop.c
+++ src/gcc/ipa-prop.c
@@ -405,13 +405,18 @@  stmt_may_be_vtbl_ptr_store (gimple stmt)
     {
       tree lhs = gimple_assign_lhs (stmt);
 
-      if (TREE_CODE (lhs) == COMPONENT_REF
-	  && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1))
-	  && !AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
+      if (!AGGREGATE_TYPE_P (TREE_TYPE (lhs)))
+	{
+	  if (!POINTER_TYPE_P (TREE_TYPE (lhs)))
 	    return false;
-      /* In the future we might want to use get_base_ref_and_offset to find
-	 if there is a field corresponding to the offset and if so, proceed
-	 almost like if it was a component ref.  */
+
+	  if (TREE_CODE (lhs) == COMPONENT_REF
+	      && !DECL_VIRTUAL_P (TREE_OPERAND (lhs, 1)))
+	    return false;
+	  /* In the future we might want to use get_base_ref_and_offset to find
+	     if there is a field corresponding to the offset and if so, proceed
+	     almost like if it was a component ref.  */
+	}
     }
   return true;
 }