On 02/01/2012 03:59 AM, Richard Guenther wrote:
The patch looks ok, but I'm not sure why you do not get a cgraph node
here - cgraph doesn't really care for builtins as far as I can see. Honza?
I cannot help on this...
Don't you maybe want to handle builtins in a special way here?
Indeed, I think my patch is wrong. __builtin_prefetch should have the
transaction_pure attribute. I don't know how usually it should be done
but what about adding a gcc_assert before to dereference node
(potentially NULL)?
How the attached patch looks like now?
(Tested on i686)
> At least those that are const/pure?
About const/pure, we cannot consider those functions as transaction_pure
because they can read global and shared variable.
BTW, I will post a PR (and probably a patch) about this.
Thanks for your comment!
Patrick.
PR middle-end/52047
* trans-mem.c (expand_call_tm): Add an assertion.
* tree-ssa-loop-prefetch.c (issue_prefetch_ref): Add transaction_pure
attribute to __builtin_prefetch.
(tree_ssa_prefetch_arrays): Likewise.
Index: tree-ssa-loop-prefetch.c
===================================================================
--- tree-ssa-loop-prefetch.c (revision 183736)
+++ tree-ssa-loop-prefetch.c (working copy)
@@ -1,5 +1,5 @@
/* Array prefetching.
- Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011
+ Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011, 2012
Free Software Foundation, Inc.
This file is part of GCC.
@@ -1096,6 +1096,8 @@ issue_prefetch_ref (struct mem_ref *ref, unsigned
for (ap = 0; ap < n_prefetches; ap++)
{
+ tree decl;
+
if (cst_and_fits_in_hwi (ref->group->step))
{
/* Determine the address to prefetch. */
@@ -1116,9 +1118,11 @@ issue_prefetch_ref (struct mem_ref *ref, unsigned
addr = force_gimple_operand_gsi (&bsi, unshare_expr (addr), true,
NULL, true, GSI_SAME_STMT);
}
+ decl = builtin_decl_explicit (BUILT_IN_PREFETCH);
+ if (flag_tm)
+ apply_tm_attr (decl, get_identifier ("transaction_pure"));
/* Create the prefetch instruction. */
- prefetch = gimple_build_call (builtin_decl_explicit (BUILT_IN_PREFETCH),
- 3, addr, write_p, local);
+ prefetch = gimple_build_call (decl, 3, addr, write_p, local);
gsi_insert_before (&bsi, prefetch, GSI_SAME_STMT);
}
}
@@ -1917,6 +1921,8 @@ tree_ssa_prefetch_arrays (void)
BUILT_IN_PREFETCH, BUILT_IN_NORMAL,
NULL, NULL_TREE);
DECL_IS_NOVOPS (decl) = true;
+ if (flag_tm)
+ apply_tm_attr (decl, get_identifier ("transaction_pure"));
set_builtin_decl (BUILT_IN_PREFETCH, decl, false);
}
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 183736)
+++ trans-mem.c (working copy)
@@ -1,5 +1,5 @@
/* Passes for transactional memory support.
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
This file is part of GCC.
@@ -2267,6 +2267,7 @@ expand_call_tm (struct tm_region *region,
}
node = cgraph_get_node (fn_decl);
+ gcc_assert (node);
if (node->local.tm_may_enter_irr)
transaction_subcode_ior (region, GTMA_MAY_ENTER_IRREVOCABLE);
Index: testsuite/gcc.dg/tm/pr52047.c
===================================================================
--- testsuite/gcc.dg/tm/pr52047.c (revision 0)
+++ testsuite/gcc.dg/tm/pr52047.c (revision 0)
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgnu-tm -fprefetch-loop-arrays -w" } */
+
+int test2 (int x[])
+{
+ return x[12];
+}
+
+int test1 (void)
+{
+ int x[1000], i;
+ for (i = 0; i < 1000; i++)
+ x[i] = i;
+ return test2 (x);
+}
+
+int
+main ()
+{
+ __transaction_atomic
+ {
+ if (test1 ())
+ __transaction_cancel;
+ }
+ return 0;
+}