This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Properly disregard non-aliased variables in ref_maybe_used_by_call_p_1 and call_may_clobber_ref_p_1


non-aliased variables are not used by calls if they are not passed
by value.  Likewise non-aliased variables are not clobbered by calls.

The complication starts with local statics (as I looked at the
189.lucas regression I noticed most variables there are saved).  But
here we can avoid clobbering by malloc calls by assuming that calls
to builtin function will not re-enter the current function (and thus
read or clobber local statics).  At least if we are not also a builtin
function.

Bootstrapped and tested on x86_64-unknown-linux-gnu - this should make
some real difference at least for lucas.  Applied to trunk.

Richard.

2009-04-07  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-alias.c (ref_maybe_used_by_call_p_1): Non-aliased
	decls are only used if passes as parameters or if they are
	local statics and the call is not to a builtin.
	(call_may_clobber_ref_p_1): Likewise.

Index: gcc/tree-ssa-alias.c
===================================================================
*** gcc/tree-ssa-alias.c	(revision 145659)
--- gcc/tree-ssa-alias.c	(working copy)
*************** refs_may_alias_p (tree ref1, tree ref2)
*** 737,743 ****
  static bool
  ref_maybe_used_by_call_p_1 (gimple call, tree ref)
  {
!   tree base;
    unsigned i;
    int flags = gimple_call_flags (call);
  
--- 737,743 ----
  static bool
  ref_maybe_used_by_call_p_1 (gimple call, tree ref)
  {
!   tree base, fndecl;
    unsigned i;
    int flags = gimple_call_flags (call);
  
*************** ref_maybe_used_by_call_p_1 (gimple call,
*** 754,759 ****
--- 754,773 ----
        || !DECL_P (base))
      return true;
  
+   /* If the reference is based on a decl that is not aliased the call
+      cannot possibly use it.  */
+   if (DECL_P (base)
+       && !may_be_aliased (base)
+       /* But local statics can be used through recursion!  */
+       && (!is_global_var (base)
+ 	  /* But not via builtins.
+ 	     ???  We just assume that this is true if we are not a
+ 	     builtin function ourself.  */
+ 	  || (!DECL_BUILT_IN (cfun->decl)
+ 	      && (fndecl = gimple_call_fndecl (call))
+ 	      && DECL_BUILT_IN (fndecl))))
+     goto process_args;
+ 
    /* Check if base is a global static variable that is not read
       by the function.  */
    if (TREE_CODE (base) == VAR_DECL
*************** ref_maybe_used_by_stmt_p (gimple stmt, t
*** 851,857 ****
  static bool
  call_may_clobber_ref_p_1 (gimple call, tree ref)
  {
!   tree base;
  
    /* If the call is pure or const it cannot clobber anything.  */
    if (gimple_call_flags (call)
--- 865,871 ----
  static bool
  call_may_clobber_ref_p_1 (gimple call, tree ref)
  {
!   tree fndecl, base;
  
    /* If the call is pure or const it cannot clobber anything.  */
    if (gimple_call_flags (call)
*************** call_may_clobber_ref_p_1 (gimple call, t
*** 866,871 ****
--- 880,900 ----
        || CONSTANT_CLASS_P (base))
      return false;
  
+   /* If the reference is based on a decl that is not aliased the call
+      cannot possibly clobber it.  */
+   if (DECL_P (base)
+       && !may_be_aliased (base)
+       /* But local non-readonly statics can be modified through recursion!  */
+       && (TREE_READONLY (base)
+ 	  || !is_global_var (base)
+ 	  /* But not via builtins.
+ 	     ???  We just assume that this is true if we are not a
+ 	     builtin function ourself.  */
+ 	  || (!DECL_BUILT_IN (cfun->decl)
+ 	      && (fndecl = gimple_call_fndecl (call))
+ 	      && DECL_BUILT_IN (fndecl))))
+     return false;
+ 
    /* Check if base is a global static variable that is not written
       by the function.  */
    if (TREE_CODE (base) == VAR_DECL


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]