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