From 0dcf7faed80de1fc3fa58265f0a247e23ad22f14 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-inline.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 32c49ae..8c5d5da 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -3670,11 +3670,9 @@ declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, if (TREE_ADDRESSABLE (result)) mark_addressable (var); } - if ((TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE - || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE) - && !DECL_GIMPLE_REG_P (result) + if (DECL_NOT_GIMPLE_REG_P (result) && DECL_P (var)) - DECL_GIMPLE_REG_P (var) = 0; + DECL_NOT_GIMPLE_REG_P (var) = 1; if (!useless_type_conversion_p (callee_type, caller_type)) var = build1 (VIEW_CONVERT_EXPR, callee_type, var); @@ -3717,10 +3715,8 @@ declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, use_it = false; else if (is_global_var (base_m)) use_it = false; - else if ((TREE_CODE (TREE_TYPE (result)) == COMPLEX_TYPE - || TREE_CODE (TREE_TYPE (result)) == VECTOR_TYPE) - && !DECL_GIMPLE_REG_P (result) - && DECL_GIMPLE_REG_P (base_m)) + else if (DECL_NOT_GIMPLE_REG_P (result) + && !DECL_NOT_GIMPLE_REG_P (base_m)) use_it = false; else if (!TREE_ADDRESSABLE (base_m)) use_it = true; @@ -3760,11 +3756,8 @@ declare_return_variable (copy_body_data *id, tree return_slot, tree modify_dest, to using a MEM_REF to not leak invalid GIMPLE to the following passes. */ /* Prevent var from being written into SSA form. */ - if (TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE - || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE) - DECL_GIMPLE_REG_P (var) = false; - else if (is_gimple_reg_type (TREE_TYPE (var))) - TREE_ADDRESSABLE (var) = true; + if (is_gimple_reg_type (TREE_TYPE (var))) + DECL_NOT_GIMPLE_REG_P (var) = true; use = fold_build2 (MEM_REF, caller_type, build_fold_addr_expr (var), build_int_cst (ptr_type_node, 0)); @@ -5930,7 +5923,7 @@ copy_decl_to_var (tree decl, copy_body_data *id) TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl); TREE_READONLY (copy) = TREE_READONLY (decl); TREE_THIS_VOLATILE (copy) = TREE_THIS_VOLATILE (decl); - DECL_GIMPLE_REG_P (copy) = DECL_GIMPLE_REG_P (decl); + DECL_NOT_GIMPLE_REG_P (copy) = DECL_NOT_GIMPLE_REG_P (decl); DECL_BY_REFERENCE (copy) = DECL_BY_REFERENCE (decl); return copy_decl_for_dup_finish (id, decl, copy); @@ -5960,7 +5953,12 @@ copy_result_decl_to_var (tree decl, copy_body_data *id) if (!DECL_BY_REFERENCE (decl)) { TREE_ADDRESSABLE (copy) = TREE_ADDRESSABLE (decl); - DECL_GIMPLE_REG_P (copy) = DECL_GIMPLE_REG_P (decl); + DECL_NOT_GIMPLE_REG_P (copy) + = (DECL_NOT_GIMPLE_REG_P (decl) + /* RESULT_DECLs are treated special by needs_to_live_in_memory, + mirror that to the created VAR_DECL. */ + || (TREE_CODE (decl) == RESULT_DECL + && aggregate_value_p (decl, id->src_fn))); } return copy_decl_for_dup_finish (id, decl, copy); -- cgit v1.1 From 3cf48501ec23c55e66e9eaf698778ad6ca053183 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 14 May 2020 09:58:53 +0200 Subject: openmp: cgraph support for late declare variant resolution This is a new version of the https://gcc.gnu.org/legacy-ml/gcc-patches/2019-11/msg01493.html patch. Unlike the previous version, this one actually works properly except for LTO, bootstrapped/regtested on x86_64-linux and i686-linux too. In short, #pragma omp declare variant is a directive which allows redirection of direct calls to certain function to other calls with a scoring system and some of those decisions need to be deferred until after IPA. The patch represents them with calls to an artificial FUNCTION_DECL with declare_variant_alt in the cgraph_node set. For LTO, the patch only saves/restores the two cgraph_node bits added in the patch, but doesn't yet stream out and back in the on the side info for the declare_variant_alt. For the LTO partitioning, I believe those artificial FUNCTION_DECLs with declare_variant_alt need to go into partition together with anything that calls them (possibly duplicated), any way how to achieve that? Say if declare variant artificial fn foobar is directly called from all of foo, bar and baz and not from qux and we want 4 partitions, one for each of foo, bar, baz, qux, then foobar is needed in the first 3 partitions, and the IPA_REF_ADDRs recorded for foobar that right after IPA the foobar call will be replaced with calls to foobar1, foobar2, foobar3 or foobar (non-artificial) can of course stay in different partitions if needed. 2020-05-14 Jakub Jelinek * Makefile.in (GTFILES): Add omp-general.c. * cgraph.h (struct cgraph_node): Add declare_variant_alt and calls_declare_variant_alt members and initialize them in the ctor. * ipa.c (symbol_table::remove_unreachable_nodes): Handle direct calls to declare_variant_alt nodes. * lto-cgraph.c (lto_output_node): Write declare_variant_alt and calls_declare_variant_alt. (input_overwrite_node): Read them back. * omp-simd-clone.c (simd_clone_create): Copy calls_declare_variant_alt bit. * tree-inline.c (expand_call_inline): Or in calls_declare_variant_alt bit. (tree_function_versioning): Copy calls_declare_variant_alt bit. * omp-offload.c (execute_omp_device_lower): Call omp_resolve_declare_variant on direct function calls. (pass_omp_device_lower::gate): Also enable for calls_declare_variant_alt functions. * omp-general.c (omp_maybe_offloaded): Return false after inlining. (omp_context_selector_matches): Handle the case when cfun->curr_properties has PROP_gimple_any bit set. (struct omp_declare_variant_entry): New type. (struct omp_declare_variant_base_entry): New type. (struct omp_declare_variant_hasher): New type. (omp_declare_variant_hasher::hash, omp_declare_variant_hasher::equal): New methods. (omp_declare_variants): New variable. (struct omp_declare_variant_alt_hasher): New type. (omp_declare_variant_alt_hasher::hash, omp_declare_variant_alt_hasher::equal): New methods. (omp_declare_variant_alt): New variables. (omp_resolve_late_declare_variant): New function. (omp_resolve_declare_variant): Call omp_resolve_late_declare_variant when called late. Create a magic declare_variant_alt fndecl and cgraph node and return that if decision needs to be deferred until after gimplification. * cgraph.c (symbol_table::create_edge): Or in calls_declare_variant_alt bit. * c-c++-common/gomp/declare-variant-14.c: New test. --- gcc/tree-inline.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 8c5d5da..ee96c9c 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -4900,6 +4900,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id, if (src_properties != prop_mask) dst_cfun->curr_properties &= src_properties | ~prop_mask; dst_cfun->calls_eh_return |= id->src_cfun->calls_eh_return; + id->dst_node->calls_declare_variant_alt + |= id->src_node->calls_declare_variant_alt; gcc_assert (!id->src_cfun->after_inlining); @@ -6231,6 +6233,8 @@ tree_function_versioning (tree old_decl, tree new_decl, DECL_ARGUMENTS (new_decl) = DECL_ARGUMENTS (old_decl); initialize_cfun (new_decl, old_decl, new_entry ? new_entry->count : old_entry_block->count); + new_version_node->calls_declare_variant_alt + = old_version_node->calls_declare_variant_alt; if (DECL_STRUCT_FUNCTION (new_decl)->gimple_df) DECL_STRUCT_FUNCTION (new_decl)->gimple_df->ipa_pta = id.src_cfun->gimple_df->ipa_pta; -- cgit v1.1 From 804937f5b730ee7c1ec5e32fbfad1f07840076cc Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 18 May 2020 08:51:23 +0200 Subject: middle-end/95171 - inlining of trapping compare into non-call EH fn This fixes always-inlining across -fnon-call-exception boundaries for conditions which we do not allow to throw. 2020-05-18 Richard Biener PR middle-end/95171 * tree-inline.c (remap_gimple_stmt): Split out trapping compares when inlining into a non-call EH function. * gcc.dg/pr95171.c: New testcase. --- gcc/tree-inline.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index ee96c9c..943f3f9 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1956,6 +1956,37 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) gimple_set_vuse (copy, NULL_TREE); } + if (cfun->can_throw_non_call_exceptions) + { + /* When inlining a function which does not have non-call exceptions + enabled into a function that has (which only happens with + always-inline) we have to fixup stmts that cannot throw. */ + if (gcond *cond = dyn_cast (copy)) + if (gimple_could_trap_p (cond)) + { + gassign *cmp + = gimple_build_assign (make_ssa_name (boolean_type_node), + gimple_cond_code (cond), + gimple_cond_lhs (cond), + gimple_cond_rhs (cond)); + gimple_seq_add_stmt (&stmts, cmp); + gimple_cond_set_code (cond, NE_EXPR); + gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp)); + gimple_cond_set_rhs (cond, boolean_false_node); + } + if (gassign *ass = dyn_cast (copy)) + if ((gimple_assign_rhs_code (ass) == COND_EXPR + || gimple_assign_rhs_code (ass) == VEC_COND_EXPR) + && gimple_could_trap_p (ass)) + { + gassign *cmp + = gimple_build_assign (make_ssa_name (boolean_type_node), + gimple_assign_rhs1 (ass)); + gimple_seq_add_stmt (&stmts, cmp); + gimple_assign_set_rhs1 (ass, gimple_assign_lhs (cmp)); + } + } + gimple_seq_add_stmt (&stmts, copy); return stmts; } -- cgit v1.1 From 9bd060e0ea8031cc323a7a6200f934ea7b4fc55a Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 20 May 2020 11:00:57 +0200 Subject: middle-end/95231 - revert parts of PR95171 I mistook the opportunity to also "fix" the [VEC_]COND_EXPR case for PR95171 but I was wrong in that it doesn't need the fix and in the actual fix as well. The following just reverts that part. 2020-05-20 Richard Biener PR middle-end/95231 * tree-inline.c (remap_gimple_stmt): Revert adjusting COND_EXPR and VEC_COND_EXPR for a -fnon-call-exception boundary. * g++.dg/other/pr95231.C: New testcase. --- gcc/tree-inline.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'gcc/tree-inline.c') diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 943f3f9..3160ca3 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1974,17 +1974,6 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id) gimple_cond_set_lhs (cond, gimple_assign_lhs (cmp)); gimple_cond_set_rhs (cond, boolean_false_node); } - if (gassign *ass = dyn_cast (copy)) - if ((gimple_assign_rhs_code (ass) == COND_EXPR - || gimple_assign_rhs_code (ass) == VEC_COND_EXPR) - && gimple_could_trap_p (ass)) - { - gassign *cmp - = gimple_build_assign (make_ssa_name (boolean_type_node), - gimple_assign_rhs1 (ass)); - gimple_seq_add_stmt (&stmts, cmp); - gimple_assign_set_rhs1 (ass, gimple_assign_lhs (cmp)); - } } gimple_seq_add_stmt (&stmts, copy); -- cgit v1.1