From feca8f5a964a16efbe7c9ca22cd8c2539e0f00e9 Mon Sep 17 00:00:00 2001 From: Torvald Riegel <triegel@redhat.com> Date: Mon, 12 Dec 2011 12:04:46 +0000 Subject: [PATCH] Prevent sharing of commit calls among transactions. gcc/ * tree-ssa-tail-merge.c (gimple_equal_p): Don't treat transaction commits as equal. gcc/testsuite/ * c-c++-common/tm/20111206.c: New test. From-SVN: r182231 --- gcc/ChangeLog | 5 +++ gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/c-c++-common/tm/20111206.c | 53 ++++++++++++++++++++++++ gcc/tree-ssa-tail-merge.c | 8 ++++ 4 files changed, 70 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/tm/20111206.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9e0e3f0633fc..eed29f04cce5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2011-12-12 Torvald Riegel <triegel@redhat.com> + + * tree-ssa-tail-merge.c (gimple_equal_p): Don't treat transaction + commits as equal. + 2011-12-12 Iain Sandoe <iains@gcc.gnu.org> * config/darwin-sections.def (zobj_const_data_section): Fix over- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1d78adfdb8c9..e6f64a774d1d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2011-12-12 Torvald Riegel <triegel@redhat.com> + + * c-c++-common/tm/20111206.c: New test. + 2011-12-12 Richard Guenther <rguenther@suse.de> PR lto/51262 diff --git a/gcc/testsuite/c-c++-common/tm/20111206.c b/gcc/testsuite/c-c++-common/tm/20111206.c new file mode 100644 index 000000000000..74a551966f26 --- /dev/null +++ b/gcc/testsuite/c-c++-common/tm/20111206.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm -O2" } */ +/* This test case triggered block sharing between the two transactions. */ + +void func1 (void) __attribute__ ((transaction_callable, used)); +long func2 (void) __attribute__ ((transaction_callable, used)); +unsigned long rand (void); + +void client_run (void) +{ + long types[100]; + long i; + + for (i = 0; i < 100; i++) + { + long action = rand (); + + switch (action) + { + case 0: + { + __transaction_relaxed + { + long bill = func2 (); + if (bill >= 0) + { + func1 (); + } + } + break; + } + + case 1: + { + long n; + __transaction_relaxed + { + for (n = 0; n < 100; n++) + { + long t = types[n]; + switch (t) + { + case 0: + func1 (); + break; + } + } + } + break; + } + } + } +} diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c index a501b0778a20..7452266af2bd 100644 --- a/gcc/tree-ssa-tail-merge.c +++ b/gcc/tree-ssa-tail-merge.c @@ -1051,6 +1051,14 @@ gimple_equal_p (same_succ same_succ, gimple s1, gimple s2) if (!gimple_call_same_target_p (s1, s2)) return false; + /* Eventually, we'll significantly complicate the CFG by adding + back edges to properly model the effects of transaction restart. + For the bulk of optimization this does not matter, but what we + cannot recover from is tail merging blocks between two separate + transactions. Avoid that by making commit not match. */ + if (gimple_call_builtin_p (s1, BUILT_IN_TM_COMMIT)) + return false; + equal = true; for (i = 0; i < gimple_call_num_args (s1); ++i) { -- GitLab