https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104303

--- Comment #6 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
OK, tree-ssa-alias is using:

if (ref_may_access_global_memory_p (ref))

to determine if the access to S9b.6_22 may be used by the call.  I expected
this to return true because memory pointed to S9b.6_22 is escaping and thus it
is accessible from global memory accesses.

However the implementation does:

/* Return ture if REF may access global memory.  */                             

bool                                                                            
ref_may_access_global_memory_p (ao_ref *ref)                                    
{                                                                               
  if (!ref->ref)                                                                
    return true;                                                                
  tree base = ao_ref_base (ref);                                                
  if (TREE_CODE (base) == MEM_REF                                               
      || TREE_CODE (base) == TARGET_MEM_REF)                                    
    {                                                                           
      if (ptr_deref_may_alias_global_p (TREE_OPERAND (base, 0)))                
        return true;                                                            
    }                                                                           
  else                                                                          
    {                                                                           
      if (!auto_var_in_fn_p (base, current_function_decl)                       
          || pt_solution_includes (&cfun->gimple_df->escaped,                   
                                   base))                                       
        return true;                                                            
    }                                                                           
  return false;                                                                 
}                                                                               


so for automatic variables we check "escaped" flag, but since this is heap
alocated we go the ptr_deref_may_alias_global_p path which checks:

/* Return true, if dereferencing PTR may alias with a global variable.  */      

bool                                                                            
ptr_deref_may_alias_global_p (tree ptr)                                         
{                                                                               
  struct ptr_info_def *pi;                                                      

  /* If we end up with a pointer constant here that may point                   
     to global memory.  */                                                      
  if (TREE_CODE (ptr) != SSA_NAME)                                              
    return true;                                                                

  pi = SSA_NAME_PTR_INFO (ptr);                                                 

  /* If we do not have points-to information for this variable,                 
     we have to punt.  */                                                       
  if (!pi)                                                                      
    return true;                                                                

  /* ???  This does not use TBAA to prune globals ptr may not access.  */       
  return pt_solution_includes_global (&pi->pt);                                 
}                                                                               

So this predicate tests something different - it tests if the deref can alias
global variable, not global memory in a sense of anything accessible from
outside world.

So I want to also return true on points to set that contains escaped?

diff --git a/gcc/tree-ssa-alias.cc b/gcc/tree-ssa-alias.cc
index 50bd47b31f3..9e34f76c3cb 100644
--- a/gcc/tree-ssa-alias.cc
+++ b/gcc/tree-ssa-alias.cc
@@ -2578,8 +2578,24 @@ ref_may_access_global_memory_p (ao_ref *ref)
   if (TREE_CODE (base) == MEM_REF
       || TREE_CODE (base) == TARGET_MEM_REF)
     {
-      if (ptr_deref_may_alias_global_p (TREE_OPERAND (base, 0)))
+      struct ptr_info_def *pi;
+      tree ptr = TREE_OPERAND (base, 0);
+
+      /* If we end up with a pointer constant here that may point
+        to global memory.  */
+      if (TREE_CODE (ptr) != SSA_NAME)
+       return true;
+
+      pi = SSA_NAME_PTR_INFO (ptr);
+
+      /* If we do not have points-to information for this variable,
+        we have to punt.  */
+      if (!pi)
        return true;
+
+      /* ???  This does not use TBAA to prune globals ptr may not access.  */
+      return pt_solution_includes_global (&pi->pt)
+            || pi->pt.vars_contains_escaped;
     }
   else
     {

Reply via email to