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; +}