From 9c3cdb43c2bdaf8a8d2e62db010b04f6086d76b7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sun, 15 Mar 2020 01:27:40 +0100 Subject: tree-nested: Fix handling of *reduction clauses with C array sections [PR93566] tree-nested.c didn't handle C array sections in {,task_,in_}reduction clauses. 2020-03-14 Jakub Jelinek PR middle-end/93566 * tree-nested.c (convert_nonlocal_omp_clauses, convert_local_omp_clauses): Handle {,in_,task_}reduction clauses with C/C++ array sections. * testsuite/libgomp.c/pr93566.c: New test. --- gcc/tree-nested.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'gcc/tree-nested.c') diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 2bb1106..6f696da 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -1188,7 +1188,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_chain = false, need_stmts = false; - tree clause, decl; + tree clause, decl, *pdecl; int dummy; bitmap new_suppress; @@ -1197,6 +1197,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { case OMP_CLAUSE_REDUCTION: @@ -1204,6 +1205,15 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_TASK_REDUCTION: if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause)) need_stmts = true; + if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF) + { + pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0); + if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + if (TREE_CODE (*pdecl) == INDIRECT_REF + || TREE_CODE (*pdecl) == ADDR_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + } goto do_decl_clause; case OMP_CLAUSE_LASTPRIVATE: @@ -1230,7 +1240,9 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_USE_DEVICE_ADDR: case OMP_CLAUSE_IS_DEVICE_PTR: do_decl_clause: - decl = OMP_CLAUSE_DECL (clause); + if (pdecl == NULL) + pdecl = &OMP_CLAUSE_DECL (clause); + decl = *pdecl; if (VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) break; @@ -1239,7 +1251,7 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED) OMP_CLAUSE_SHARED_READONLY (clause) = 0; bitmap_set_bit (new_suppress, DECL_UID (decl)); - OMP_CLAUSE_DECL (clause) = get_nonlocal_debug_decl (info, decl); + *pdecl = get_nonlocal_debug_decl (info, decl); if (OMP_CLAUSE_CODE (clause) != OMP_CLAUSE_PRIVATE) need_chain = true; } @@ -1909,7 +1921,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) { struct nesting_info *const info = (struct nesting_info *) wi->info; bool need_frame = false, need_stmts = false; - tree clause, decl; + tree clause, decl, *pdecl; int dummy; bitmap new_suppress; @@ -1918,6 +1930,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) for (clause = *pclauses; clause ; clause = OMP_CLAUSE_CHAIN (clause)) { + pdecl = NULL; switch (OMP_CLAUSE_CODE (clause)) { case OMP_CLAUSE_REDUCTION: @@ -1925,6 +1938,15 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_TASK_REDUCTION: if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (clause)) need_stmts = true; + if (TREE_CODE (OMP_CLAUSE_DECL (clause)) == MEM_REF) + { + pdecl = &TREE_OPERAND (OMP_CLAUSE_DECL (clause), 0); + if (TREE_CODE (*pdecl) == POINTER_PLUS_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + if (TREE_CODE (*pdecl) == INDIRECT_REF + || TREE_CODE (*pdecl) == ADDR_EXPR) + pdecl = &TREE_OPERAND (*pdecl, 0); + } goto do_decl_clause; case OMP_CLAUSE_LASTPRIVATE: @@ -1951,7 +1973,9 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_USE_DEVICE_ADDR: case OMP_CLAUSE_IS_DEVICE_PTR: do_decl_clause: - decl = OMP_CLAUSE_DECL (clause); + if (pdecl == NULL) + pdecl = &OMP_CLAUSE_DECL (clause); + decl = *pdecl; if (VAR_P (decl) && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))) break; @@ -1964,8 +1988,7 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_SHARED) OMP_CLAUSE_SHARED_READONLY (clause) = 0; bitmap_set_bit (new_suppress, DECL_UID (decl)); - OMP_CLAUSE_DECL (clause) - = get_local_debug_decl (info, decl, field); + *pdecl = get_local_debug_decl (info, decl, field); need_frame = true; } } -- cgit v1.1 From eb72dc663e9070b281be83a80f6f838a3a878822 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 22 Apr 2020 10:40:51 +0200 Subject: extend DECL_GIMPLE_REG_P to all types This extends DECL_GIMPLE_REG_P to all types so we can clear TREE_ADDRESSABLE even for integers with partial defs, not just complex and vector variables. To make that transition easier the patch inverts DECL_GIMPLE_REG_P to DECL_NOT_GIMPLE_REG_P since that makes the default the current state for all other types besides complex and vectors. For the testcase in PR94703 we're able to expand the partial def'ed local integer to a register then, producing a single movl rather than going through the stack. On i?86 this execute FAILs gcc.dg/torture/pr71522.c because we now expand a round-trip through a long double automatic var to a register fld/fst which normalizes the value. For that during RTL expansion we're looking for problematic punnings of decls and avoid pseudos for those - I chose integer or BLKmode accesses on decls with modes where precision doesn't match bitsize which covers the XFmode case. 2020-05-07 Richard Biener PR middle-end/94703 * tree-core.h (tree_decl_common::gimple_reg_flag): Rename ... (tree_decl_common::not_gimple_reg_flag): ... to this. * tree.h (DECL_GIMPLE_REG_P): Rename ... (DECL_NOT_GIMPLE_REG_P): ... to this. * gimple-expr.c (copy_var_decl): Copy DECL_NOT_GIMPLE_REG_P. (create_tmp_reg): Simplify. (create_tmp_reg_fn): Likewise. (is_gimple_reg): Check DECL_NOT_GIMPLE_REG_P for all regs. * gimplify.c (create_tmp_from_val): Simplify. (gimplify_bind_expr): Likewise. (gimplify_compound_literal_expr): Likewise. (gimplify_function_tree): Likewise. (prepare_gimple_addressable): Set DECL_NOT_GIMPLE_REG_P. * asan.c (create_odr_indicator): Do not clear DECL_GIMPLE_REG_P. (asan_add_global): Copy it. * cgraphunit.c (cgraph_node::expand_thunk): Force args to be GIMPLE regs. * function.c (gimplify_parameters): Copy DECL_NOT_GIMPLE_REG_P. * ipa-param-manipulation.c (ipa_param_body_adjustments::common_initialization): Simplify. (ipa_param_body_adjustments::reset_debug_stmts): Copy DECL_NOT_GIMPLE_REG_P. * omp-low.c (lower_omp_for_scan): Do not set DECL_GIMPLE_REG_P. * sanopt.c (sanitize_rewrite_addressable_params): Likewise. * tree-cfg.c (make_blocks_1): Simplify. (verify_address): Do not verify DECL_GIMPLE_REG_P setting. * tree-eh.c (lower_eh_constructs_2): Simplify. * tree-inline.c (declare_return_variable): Adjust and generalize. (copy_decl_to_var): Copy DECL_NOT_GIMPLE_REG_P. (copy_result_decl_to_var): Likewise. * tree-into-ssa.c (pass_build_ssa::execute): Adjust comment. * tree-nested.c (create_tmp_var_for): Simplify. * tree-parloops.c (separate_decls_in_region_name): Copy DECL_NOT_GIMPLE_REG_P. * tree-sra.c (create_access_replacement): Adjust and generalize partial def support. * tree-ssa-forwprop.c (pass_forwprop::execute): Set DECL_NOT_GIMPLE_REG_P on decls we introduce partial defs on. * tree-ssa.c (maybe_optimize_var): Handle clearing of TREE_ADDRESSABLE and setting/clearing DECL_NOT_GIMPLE_REG_P independently. * lto-streamer-out.c (hash_tree): Hash DECL_NOT_GIMPLE_REG_P. * tree-streamer-out.c (pack_ts_decl_common_value_fields): Stream DECL_NOT_GIMPLE_REG_P. * tree-streamer-in.c (unpack_ts_decl_common_value_fields): Likewise. * cfgexpand.c (avoid_type_punning_on_regs): New. (discover_nonconstant_array_refs): Call avoid_type_punning_on_regs to avoid unsupported mode punning. lto/ * lto-common.c (compare_tree_sccs_1): Compare DECL_NOT_GIMPLE_REG_P. c/ * gimple-parser.c (c_parser_parse_ssa_name): Do not set DECL_GIMPLE_REG_P. cp/ * optimize.c (update_cloned_parm): Copy DECL_NOT_GIMPLE_REG_P. * gcc.dg/tree-ssa/pr94703.c: New testcase. --- gcc/tree-nested.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'gcc/tree-nested.c') diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index 6f696da..de168df 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -160,9 +160,6 @@ create_tmp_var_for (struct nesting_info *info, tree type, const char *prefix) DECL_CONTEXT (tmp_var) = info->context; DECL_CHAIN (tmp_var) = info->new_local_var_chain; DECL_SEEN_IN_BIND_EXPR_P (tmp_var) = 1; - if (TREE_CODE (type) == COMPLEX_TYPE - || TREE_CODE (type) == VECTOR_TYPE) - DECL_GIMPLE_REG_P (tmp_var) = 1; info->new_local_var_chain = tmp_var; -- cgit v1.1