int index)
{
tree loadedi, storedi, initial, new_storedi, old_vali;
- tree type, itype, cmpxchg, iaddr;
+ tree type, itype, cmpxchg, iaddr, atype;
gimple_stmt_iterator si;
basic_block loop_header = single_succ (load_bb);
gimple *phi, *stmt;
cmpxchg = builtin_decl_explicit (fncode);
if (cmpxchg == NULL_TREE)
return false;
- type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr)));
+ type = TYPE_MAIN_VARIANT (TREE_TYPE (loaded_val));
+ atype = type;
itype = TREE_TYPE (TREE_TYPE (cmpxchg));
if (!can_compare_and_swap_p (TYPE_MODE (itype), true)
iaddr = create_tmp_reg (build_pointer_type_for_mode (itype, ptr_mode,
true));
+ atype = itype;
iaddr_val
= force_gimple_operand_gsi (&si,
fold_convert (TREE_TYPE (iaddr), addr),
tree loaddecl = builtin_decl_explicit (fncode);
if (loaddecl)
initial
- = fold_convert (TREE_TYPE (TREE_TYPE (iaddr)),
+ = fold_convert (atype,
build_call_expr (loaddecl, 2, iaddr,
build_int_cst (NULL_TREE,
MEMMODEL_RELAXED)));
else
- initial = build2 (MEM_REF, TREE_TYPE (TREE_TYPE (iaddr)), iaddr,
- build_int_cst (TREE_TYPE (iaddr), 0));
+ {
+ tree off
+ = build_int_cst (build_pointer_type_for_mode (atype, ptr_mode,
+ true), 0);
+ initial = build2 (MEM_REF, atype, iaddr, off);
+ }
initial
= force_gimple_operand_gsi (&si, initial, true, NULL_TREE, true,
t = build_call_expr (t, 0);
force_gimple_operand_gsi (&si, t, true, NULL_TREE, true, GSI_SAME_STMT);
- stmt = gimple_build_assign (loaded_val, build_simple_mem_ref (addr));
+ tree mem = build_simple_mem_ref (addr);
+ TREE_TYPE (mem) = TREE_TYPE (loaded_val);
+ TREE_OPERAND (mem, 1)
+ = fold_convert (build_pointer_type_for_mode (TREE_TYPE (mem), ptr_mode,
+ true),
+ TREE_OPERAND (mem, 1));
+ stmt = gimple_build_assign (loaded_val, mem);
gsi_insert_before (&si, stmt, GSI_SAME_STMT);
gsi_remove (&si, true);
si = gsi_last_nondebug_bb (store_bb);
gcc_assert (gimple_code (gsi_stmt (si)) == GIMPLE_OMP_ATOMIC_STORE);
- stmt = gimple_build_assign (build_simple_mem_ref (unshare_expr (addr)),
- stored_val);
+ stmt = gimple_build_assign (unshare_expr (mem), stored_val);
gsi_insert_before (&si, stmt, GSI_SAME_STMT);
t = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END);
tree loaded_val = gimple_omp_atomic_load_lhs (load);
tree addr = gimple_omp_atomic_load_rhs (load);
tree stored_val = gimple_omp_atomic_store_val (store);
- tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr)));
+ tree type = TYPE_MAIN_VARIANT (TREE_TYPE (loaded_val));
HOST_WIDE_INT index;
/* Make sure the type is one of the supported sizes. */