From be7c145ad52e76a1a0fd201dd96bc92e8d3a275d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 18 Feb 2020 09:07:15 +0100 Subject: tree-ssa: Fix ICE in build_vector_type [PR93780] The following testcase ICEs, because execute_update_addresses_taken attempts to create a VECTOR_TYPE with non-power of 2 number of elts. Fixed by guarding it with the corresponding predicate. 2020-02-18 Jakub Jelinek PR tree-optimization/93780 * tree-ssa.c (non_rewritable_lvalue_p): Check valid_vector_subparts_p before calling build_vector_type. (execute_update_addresses_taken): Likewise. * gcc.dg/pr93780.c: New test. --- gcc/tree-ssa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'gcc/tree-ssa.c') diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index dbff604..344f32d 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1550,7 +1550,8 @@ non_rewritable_lvalue_p (tree lhs) && multiple_p (lhs_bits, tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))), - &nelts)) + &nelts) + && valid_vector_subparts_p (nelts)) { if (known_eq (nelts, 1u)) return false; @@ -1925,7 +1926,8 @@ execute_update_addresses_taken (void) (TYPE_SIZE (TREE_TYPE (TREE_TYPE (sym)))), &nelts) - && maybe_ne (nelts, 1u)) + && maybe_ne (nelts, 1u) + && valid_vector_subparts_p (nelts)) temtype = build_vector_type (temtype, nelts); tree tem = make_ssa_name (temtype); gimple *pun -- cgit v1.1 From f65cecabc32fe12b024253502af953e657e1a878 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Tue, 14 Apr 2020 19:42:23 +0000 Subject: PR tree-optimization/94574 - aarch64: ICE during GIMPLE pass:ccp In this PR the testcase ICEs because a BIT_INSERT_EXPR whose replaced bits are not fully inside the container is generated. A size check is added to avoid this kind of ICE. gcc/ChangeLog: PR tree-optimization/94574 * tree-ssa.c (non_rewritable_lvalue_p): Add size check when analyzing whether a vector-insert is rewritable using a BIT_INSERT_EXPR. gcc/testsuite/ChangeLog: PR tree-optimization/94574 * gcc.dg/pr94574.c: New test. --- gcc/tree-ssa.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'gcc/tree-ssa.c') diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 344f32d..4f4ab2b 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1543,7 +1543,9 @@ non_rewritable_lvalue_p (tree lhs) && known_gt (wi::to_poly_offset (TYPE_SIZE_UNIT (TREE_TYPE (decl))), mem_ref_offset (lhs)) && multiple_of_p (sizetype, TREE_OPERAND (lhs, 1), - TYPE_SIZE_UNIT (TREE_TYPE (lhs)))) + TYPE_SIZE_UNIT (TREE_TYPE (lhs))) + && known_ge (wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (decl))), + wi::to_poly_offset (TYPE_SIZE (TREE_TYPE (lhs))))) { poly_uint64 lhs_bits, nelts; if (poly_int_tree_p (TYPE_SIZE (TREE_TYPE (lhs)), &lhs_bits) -- 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-ssa.c | 66 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) (limited to 'gcc/tree-ssa.c') diff --git a/gcc/tree-ssa.c b/gcc/tree-ssa.c index 4f4ab2b..c47b963 100644 --- a/gcc/tree-ssa.c +++ b/gcc/tree-ssa.c @@ -1583,8 +1583,8 @@ non_rewritable_lvalue_p (tree lhs) return true; } -/* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and - mark the variable VAR for conversion into SSA. Return true when updating +/* When possible, clear TREE_ADDRESSABLE bit, set or clear DECL_NOT_GIMPLE_REG_P + and mark the variable VAR for conversion into SSA. Return true when updating stmts is required. */ static void @@ -1597,24 +1597,11 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs, || bitmap_bit_p (addresses_taken, DECL_UID (var))) return; - if (TREE_ADDRESSABLE (var) - /* Do not change TREE_ADDRESSABLE if we need to preserve var as - a non-register. Otherwise we are confused and forget to - add virtual operands for it. */ - && (!is_gimple_reg_type (TREE_TYPE (var)) - || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE - || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE - || !bitmap_bit_p (not_reg_needs, DECL_UID (var)))) + bool maybe_reg = false; + if (TREE_ADDRESSABLE (var)) { TREE_ADDRESSABLE (var) = 0; - /* If we cleared TREE_ADDRESSABLE make sure DECL_GIMPLE_REG_P - is unset if we cannot rewrite the var into SSA. */ - if ((TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE - || TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE) - && bitmap_bit_p (not_reg_needs, DECL_UID (var))) - DECL_GIMPLE_REG_P (var) = 0; - if (is_gimple_reg (var)) - bitmap_set_bit (suitable_for_renaming, DECL_UID (var)); + maybe_reg = true; if (dump_file) { fprintf (dump_file, "No longer having address taken: "); @@ -1623,20 +1610,36 @@ maybe_optimize_var (tree var, bitmap addresses_taken, bitmap not_reg_needs, } } - if (!DECL_GIMPLE_REG_P (var) - && !bitmap_bit_p (not_reg_needs, DECL_UID (var)) - && (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE - || TREE_CODE (TREE_TYPE (var)) == VECTOR_TYPE) - && !TREE_THIS_VOLATILE (var) - && (!VAR_P (var) || !DECL_HARD_REGISTER (var))) + /* For register type decls if we do not have any partial defs + we cannot express in SSA form mark them as DECL_NOT_GIMPLE_REG_P + as to avoid SSA rewrite. For the others go ahead and mark + them for renaming. */ + if (is_gimple_reg_type (TREE_TYPE (var))) { - DECL_GIMPLE_REG_P (var) = 1; - bitmap_set_bit (suitable_for_renaming, DECL_UID (var)); - if (dump_file) + if (bitmap_bit_p (not_reg_needs, DECL_UID (var))) { - fprintf (dump_file, "Now a gimple register: "); - print_generic_expr (dump_file, var); - fprintf (dump_file, "\n"); + DECL_NOT_GIMPLE_REG_P (var) = 1; + if (dump_file) + { + fprintf (dump_file, "Has partial defs: "); + print_generic_expr (dump_file, var); + fprintf (dump_file, "\n"); + } + } + else if (DECL_NOT_GIMPLE_REG_P (var)) + { + maybe_reg = true; + DECL_NOT_GIMPLE_REG_P (var) = 0; + } + if (maybe_reg && is_gimple_reg (var)) + { + if (dump_file) + { + fprintf (dump_file, "Now a gimple register: "); + print_generic_expr (dump_file, var); + fprintf (dump_file, "\n"); + } + bitmap_set_bit (suitable_for_renaming, DECL_UID (var)); } } } @@ -1669,7 +1672,8 @@ is_asan_mark_p (gimple *stmt) return false; } -/* Compute TREE_ADDRESSABLE and DECL_GIMPLE_REG_P for local variables. */ +/* Compute TREE_ADDRESSABLE and whether we have unhandled partial defs + for local variables. */ void execute_update_addresses_taken (void) -- cgit v1.1