@@ -6283,7 +6283,7 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb,
62836283 int index )
62846284{
62856285 tree loadedi , storedi , initial , new_storedi , old_vali ;
6286- tree type , itype , cmpxchg , iaddr ;
6286+ tree type , itype , cmpxchg , iaddr , atype ;
62876287 gimple_stmt_iterator si ;
62886288 basic_block loop_header = single_succ (load_bb );
62896289 gimple * phi , * stmt ;
@@ -6297,7 +6297,8 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb,
62976297 cmpxchg = builtin_decl_explicit (fncode );
62986298 if (cmpxchg == NULL_TREE )
62996299 return false;
6300- type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr )));
6300+ type = TYPE_MAIN_VARIANT (TREE_TYPE (loaded_val ));
6301+ atype = type ;
63016302 itype = TREE_TYPE (TREE_TYPE (cmpxchg ));
63026303
63036304 if (!can_compare_and_swap_p (TYPE_MODE (itype ), true)
@@ -6317,6 +6318,7 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb,
63176318
63186319 iaddr = create_tmp_reg (build_pointer_type_for_mode (itype , ptr_mode ,
63196320 true));
6321+ atype = itype ;
63206322 iaddr_val
63216323 = force_gimple_operand_gsi (& si ,
63226324 fold_convert (TREE_TYPE (iaddr ), addr ),
@@ -6337,13 +6339,17 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb,
63376339 tree loaddecl = builtin_decl_explicit (fncode );
63386340 if (loaddecl )
63396341 initial
6340- = fold_convert (TREE_TYPE ( TREE_TYPE ( iaddr )) ,
6342+ = fold_convert (atype ,
63416343 build_call_expr (loaddecl , 2 , iaddr ,
63426344 build_int_cst (NULL_TREE ,
63436345 MEMMODEL_RELAXED )));
63446346 else
6345- initial = build2 (MEM_REF , TREE_TYPE (TREE_TYPE (iaddr )), iaddr ,
6346- build_int_cst (TREE_TYPE (iaddr ), 0 ));
6347+ {
6348+ tree off
6349+ = build_int_cst (build_pointer_type_for_mode (atype , ptr_mode ,
6350+ true), 0 );
6351+ initial = build2 (MEM_REF , atype , iaddr , off );
6352+ }
63476353
63486354 initial
63496355 = force_gimple_operand_gsi (& si , initial , true, NULL_TREE , true,
@@ -6495,15 +6501,20 @@ expand_omp_atomic_mutex (basic_block load_bb, basic_block store_bb,
64956501 t = build_call_expr (t , 0 );
64966502 force_gimple_operand_gsi (& si , t , true, NULL_TREE , true, GSI_SAME_STMT );
64976503
6498- stmt = gimple_build_assign (loaded_val , build_simple_mem_ref (addr ));
6504+ tree mem = build_simple_mem_ref (addr );
6505+ TREE_TYPE (mem ) = TREE_TYPE (loaded_val );
6506+ TREE_OPERAND (mem , 1 )
6507+ = fold_convert (build_pointer_type_for_mode (TREE_TYPE (mem ), ptr_mode ,
6508+ true),
6509+ TREE_OPERAND (mem , 1 ));
6510+ stmt = gimple_build_assign (loaded_val , mem );
64996511 gsi_insert_before (& si , stmt , GSI_SAME_STMT );
65006512 gsi_remove (& si , true);
65016513
65026514 si = gsi_last_nondebug_bb (store_bb );
65036515 gcc_assert (gimple_code (gsi_stmt (si )) == GIMPLE_OMP_ATOMIC_STORE );
65046516
6505- stmt = gimple_build_assign (build_simple_mem_ref (unshare_expr (addr )),
6506- stored_val );
6517+ stmt = gimple_build_assign (unshare_expr (mem ), stored_val );
65076518 gsi_insert_before (& si , stmt , GSI_SAME_STMT );
65086519
65096520 t = builtin_decl_explicit (BUILT_IN_GOMP_ATOMIC_END );
@@ -6532,7 +6543,7 @@ expand_omp_atomic (struct omp_region *region)
65326543 tree loaded_val = gimple_omp_atomic_load_lhs (load );
65336544 tree addr = gimple_omp_atomic_load_rhs (load );
65346545 tree stored_val = gimple_omp_atomic_store_val (store );
6535- tree type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE ( addr ) ));
6546+ tree type = TYPE_MAIN_VARIANT (TREE_TYPE (loaded_val ));
65366547 HOST_WIDE_INT index ;
65376548
65386549 /* Make sure the type is one of the supported sizes. */
0 commit comments