aboutsummaryrefslogtreecommitdiff
path: root/gcc/optabs.c
diff options
context:
space:
mode:
authorAlexander Monakov <amonakov@ispras.ru>2017-09-04 13:16:37 +0300
committerAlexander Monakov <amonakov@gcc.gnu.org>2017-09-04 13:16:37 +0300
commitd8c40eff56f69877b33c697ded756d50fde90c27 (patch)
treee4a696a0929438cfbf6c366ebc3ea949267a4f51 /gcc/optabs.c
parent1fda57cb2dc323c7d387ab0df9de708c0889be0d (diff)
downloadgcc-d8c40eff56f69877b33c697ded756d50fde90c27.zip
gcc-d8c40eff56f69877b33c697ded756d50fde90c27.tar.gz
gcc-d8c40eff56f69877b33c697ded756d50fde90c27.tar.bz2
optabs: ensure atomic_load/stores have compiler barriers
PR rtl-optimization/57448 PR target/67458 PR target/81316 * optabs.c (expand_atomic_load): Place compiler memory barriers if using atomic_load pattern. (expand_atomic_store): Likewise. testsuite/ * gcc.dg/atomic/pr80640-2.c: New testcase. * gcc.dg/atomic/pr81316.c: New testcase. From-SVN: r251643
Diffstat (limited to 'gcc/optabs.c')
-rw-r--r--gcc/optabs.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/gcc/optabs.c b/gcc/optabs.c
index b7f1e2c..b657070 100644
--- a/gcc/optabs.c
+++ b/gcc/optabs.c
@@ -6344,12 +6344,20 @@ expand_atomic_load (rtx target, rtx mem, enum memmodel model)
if (icode != CODE_FOR_nothing)
{
struct expand_operand ops[3];
+ rtx_insn *last = get_last_insn ();
+ if (is_mm_seq_cst (model))
+ expand_asm_memory_barrier ();
create_output_operand (&ops[0], target, mode);
create_fixed_operand (&ops[1], mem);
create_integer_operand (&ops[2], model);
if (maybe_expand_insn (icode, 3, ops))
- return ops[0].value;
+ {
+ if (!is_mm_relaxed (model))
+ expand_asm_memory_barrier ();
+ return ops[0].value;
+ }
+ delete_insns_since (last);
}
/* If the size of the object is greater than word size on this target,
@@ -6394,11 +6402,19 @@ expand_atomic_store (rtx mem, rtx val, enum memmodel model, bool use_release)
icode = direct_optab_handler (atomic_store_optab, mode);
if (icode != CODE_FOR_nothing)
{
+ rtx_insn *last = get_last_insn ();
+ if (!is_mm_relaxed (model))
+ expand_asm_memory_barrier ();
create_fixed_operand (&ops[0], mem);
create_input_operand (&ops[1], val, mode);
create_integer_operand (&ops[2], model);
if (maybe_expand_insn (icode, 3, ops))
- return const0_rtx;
+ {
+ if (is_mm_seq_cst (model))
+ expand_asm_memory_barrier ();
+ return const0_rtx;
+ }
+ delete_insns_since (last);
}
/* If using __sync_lock_release is a viable alternative, try it.