As discussed in the PR, the problem here is that we are using ptr_deref_may_alias_global_p() to determine if a dereferenced address escapes, whereas we were previously using the now non existent is_call_clobbered. The function ptr_deref_may_alias_global_p() does not understand SSA_NAMEs, whereas is_call_clobbered did.

Richi suggested using may_be_aliased() for DECLs.

The patch below abstracts an address_escapes_p() predicate for more generic use into the aliasing code. Using this instead of ptr_deref_may_alias_global_p() fixes all 4 TM memory optimization regressions. TM logging is now back in business.

Is this what you had in mind?  OK for trunk?
        PR other/51165
        * tree-ssa-alias.h: (address_escapes_p): Declare it.
        * tree-ssa-alias.c (address_escapes_p): New.
        * trans-mem.c (thread_private_new_memory): Use it.
        (requires_barrier): Use it.

Index: testsuite/gcc.dg/tm/memopt-3.c
===================================================================
--- testsuite/gcc.dg/tm/memopt-3.c      (revision 183072)
+++ testsuite/gcc.dg/tm/memopt-3.c      (working copy)
@@ -16,5 +16,5 @@ int f()
   return lala.x[0];
 }
 
-/* { dg-final { scan-tree-dump-times "logging: lala.x\\\[i_1\\\]" 1 "tmmark" { 
xfail *-*-* }  } } */
+/* { dg-final { scan-tree-dump-times "logging: lala.x\\\[i_1\\\]" 1 "tmmark" } 
} */
 /* { dg-final { cleanup-tree-dump "tmmark" } } */
Index: testsuite/gcc.dg/tm/memopt-5.c
===================================================================
--- testsuite/gcc.dg/tm/memopt-5.c      (revision 183072)
+++ testsuite/gcc.dg/tm/memopt-5.c      (working copy)
@@ -19,5 +19,5 @@ int f()
   return lala.x[i];
 }
 
-/* { dg-final { scan-tree-dump-times "ITM_LU\[0-9\] \\\(&lala.x\\\[55\\\]" 1 
"tmedge" { xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-times "ITM_LU\[0-9\] \\\(&lala.x\\\[55\\\]" 1 
"tmedge" } } */
 /* { dg-final { cleanup-tree-dump "tmedge" } } */
Index: testsuite/gcc.dg/tm/memopt-7.c
===================================================================
--- testsuite/gcc.dg/tm/memopt-7.c      (revision 183072)
+++ testsuite/gcc.dg/tm/memopt-7.c      (working copy)
@@ -17,6 +17,6 @@ int f()
   return lala.x[asdf];
 }
 
-/* { dg-final { scan-tree-dump-times "tm_save.\[0-9_\]+ = lala" 1 "tmedge" { 
xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump-times "lala = tm_save" 1 "tmedge" { xfail *-*-* 
} } } */
+/* { dg-final { scan-tree-dump-times "tm_save.\[0-9_\]+ = lala" 1 "tmedge" } } 
*/
+/* { dg-final { scan-tree-dump-times "lala = tm_save" 1 "tmedge" } } */
 /* { dg-final { cleanup-tree-dump "tmedge" } } */
Index: testsuite/gcc.dg/tm/memopt-4.c
===================================================================
--- testsuite/gcc.dg/tm/memopt-4.c      (revision 183072)
+++ testsuite/gcc.dg/tm/memopt-4.c      (working copy)
@@ -19,6 +19,6 @@ int f()
   return lala.x[i];
 }
 
-/* { dg-final { scan-tree-dump-times "tm_save.\[0-9_\]+ = lala.x\\\[55\\\]" 1 
"tmedge" { xfail *-*-* } } } */
-/* { dg-final { scan-tree-dump-times "lala.x\\\[55\\\] = tm_save" 1 "tmedge" { 
xfail *-*-* } } } */
+/* { dg-final { scan-tree-dump-times "tm_save.\[0-9_\]+ = lala.x\\\[55\\\]" 1 
"tmedge" } } */
+/* { dg-final { scan-tree-dump-times "lala.x\\\[55\\\] = tm_save" 1 "tmedge" } 
} */
 /* { dg-final { cleanup-tree-dump "tmedge" } } */
Index: tree-ssa-alias.c
===================================================================
--- tree-ssa-alias.c    (revision 183072)
+++ tree-ssa-alias.c    (working copy)
@@ -332,6 +332,20 @@ ptr_deref_may_alias_ref_p_1 (tree ptr, a
   return true;
 }
 
+/* Returns true if an address escapes the current function.  */
+bool
+address_escapes_p (tree x)
+{
+  x = get_base_address (x);
+  if (TREE_CODE (x) == SSA_NAME)
+    return ptr_deref_may_alias_global_p (x);
+  if (TREE_CODE (x) == MEM_REF)
+    return ptr_deref_may_alias_global_p (TREE_OPERAND (x, 0));
+  if (DECL_P (x))
+    return may_be_aliased (x);
+  return false;
+}
+
 
 /* Dump alias information on FILE.  */
 
Index: tree-ssa-alias.h
===================================================================
--- tree-ssa-alias.h    (revision 183072)
+++ tree-ssa-alias.h    (working copy)
@@ -99,6 +99,7 @@ extern tree ao_ref_base (ao_ref *);
 extern alias_set_type ao_ref_alias_set (ao_ref *);
 extern bool ptr_deref_may_alias_global_p (tree);
 extern bool ptr_derefs_may_alias_p (tree, tree);
+extern bool address_escapes_p (tree);
 extern bool refs_may_alias_p (tree, tree);
 extern bool refs_may_alias_p_1 (ao_ref *, ao_ref *, bool);
 extern bool refs_anti_dependent_p (tree, tree);
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 183072)
+++ trans-mem.c (working copy)
@@ -1347,7 +1347,7 @@ thread_private_new_memory (basic_block e
   /* Search DEF chain to find the original definition of this address.  */
   do
     {
-      if (ptr_deref_may_alias_global_p (x))
+      if (address_escapes_p (x))
        {
          /* Address escapes.  This is not thread-private.  */
          retval = mem_non_local;
@@ -1497,8 +1497,7 @@ requires_barrier (basic_block entry_bloc
             to needs_to_live_in_memory until we eliminate
             lower_sequence_tm altogether.  */
          needs_to_live_in_memory (x)
-         /* X escapes.  */
-         || ptr_deref_may_alias_global_p (x))
+         || address_escapes_p (x))
        return true;
       else
        {

Reply via email to