From bb9ec14d414a51c3461510f3cddfcafe11b35ee1 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 23 Nov 2017 08:30:41 +0000 Subject: [PATCH] re PR tree-optimization/81403 (wrong code at -O3) 2017-11-23 Richard Biener PR tree-optimization/81403 * tree-ssa-pre.c (get_representative_for): Add parameter specifying a block we need a leader relative to. (phi_translate_1): For nary processing require a leader from get_representative_for given we run expression simplification using match-and-simplify. Remove previous fix. From-SVN: r255092 --- gcc/ChangeLog | 9 ++++++ gcc/tree-ssa-pre.c | 68 ++++++++++++++++------------------------------ 2 files changed, 32 insertions(+), 45 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8d5ee90ab02..7cabfd66b93 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-11-23 Richard Biener + + PR tree-optimization/81403 + * tree-ssa-pre.c (get_representative_for): Add parameter specifying + a block we need a leader relative to. + (phi_translate_1): For nary processing require a leader from + get_representative_for given we run expression simplification + using match-and-simplify. Remove previous fix. + 2017-11-22 Jeff Law * gimple-ssa-evrp-analyze.c (evrp_range_analyzer::try_find_new_range): diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c index 477a41ed851..a9dcd5edd50 100644 --- a/gcc/tree-ssa-pre.c +++ b/gcc/tree-ssa-pre.c @@ -1257,7 +1257,7 @@ get_expr_type (const pre_expr e) gcc_unreachable (); } -/* Get a representative SSA_NAME for a given expression. +/* Get a representative SSA_NAME for a given expression that is available in B. Since all of our sub-expressions are treated as values, we require them to be SSA_NAME's for simplicity. Prior versions of GVNPRE used to use "value handles" here, so that @@ -1266,9 +1266,9 @@ get_expr_type (const pre_expr e) them to be usable without finding leaders). */ static tree -get_representative_for (const pre_expr e) +get_representative_for (const pre_expr e, basic_block b = NULL) { - tree name; + tree name, valnum = NULL_TREE; unsigned int value_id = get_expr_value_id (e); switch (e->kind) @@ -1289,7 +1289,18 @@ get_representative_for (const pre_expr e) { pre_expr rep = expression_for_id (i); if (rep->kind == NAME) - return VN_INFO (PRE_EXPR_NAME (rep))->valnum; + { + tree name = PRE_EXPR_NAME (rep); + valnum = VN_INFO (name)->valnum; + gimple *def = SSA_NAME_DEF_STMT (name); + /* We have to return either a new representative or one + that can be used for expression simplification and thus + is available in B. */ + if (! b + || gimple_nop_p (def) + || dominated_by_p (CDI_DOMINATORS, b, gimple_bb (def))) + return name; + } else if (rep->kind == CONSTANT) return PRE_EXPR_CONSTANT (rep); } @@ -1305,7 +1316,7 @@ get_representative_for (const pre_expr e) to compute it. */ name = make_temp_ssa_name (get_expr_type (e), gimple_build_nop (), "pretmp"); VN_INFO_GET (name)->value_id = value_id; - VN_INFO (name)->valnum = name; + VN_INFO (name)->valnum = valnum ? valnum : name; /* ??? For now mark this SSA name for release by SCCVN. */ VN_INFO (name)->needs_insertion = true; add_to_value (value_id, get_or_alloc_expr_for_name (name)); @@ -1356,7 +1367,9 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, leader = find_leader_in_sets (op_val_id, set1, set2); result = phi_translate (leader, set1, set2, pred, phiblock); if (result && result != leader) - newnary->op[i] = get_representative_for (result); + /* Force a leader as well as we are simplifying this + expression. */ + newnary->op[i] = get_representative_for (result, pred); else if (!result) return NULL; @@ -1398,6 +1411,10 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, return constant; } + /* vn_nary_* do not valueize operands. */ + for (i = 0; i < newnary->length; ++i) + if (TREE_CODE (newnary->op[i]) == SSA_NAME) + newnary->op[i] = VN_INFO (newnary->op[i])->valnum; tree result = vn_nary_op_lookup_pieces (newnary->length, newnary->opcode, newnary->type, @@ -1414,45 +1431,6 @@ phi_translate_1 (pre_expr expr, bitmap_set_t set1, bitmap_set_t set2, PRE_EXPR_NARY (expr) = nary; new_val_id = nary->value_id; get_or_alloc_expression_id (expr); - /* When we end up re-using a value number make sure that - doesn't have unrelated (which we can't check here) - range or points-to info on it. */ - if (result - && INTEGRAL_TYPE_P (TREE_TYPE (result)) - && SSA_NAME_RANGE_INFO (result) - && ! SSA_NAME_IS_DEFAULT_DEF (result)) - { - if (! VN_INFO (result)->info.range_info) - { - VN_INFO (result)->info.range_info - = SSA_NAME_RANGE_INFO (result); - VN_INFO (result)->range_info_anti_range_p - = SSA_NAME_ANTI_RANGE_P (result); - } - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "clearing range info of "); - print_generic_expr (dump_file, result); - fprintf (dump_file, "\n"); - } - SSA_NAME_RANGE_INFO (result) = NULL; - } - else if (result - && POINTER_TYPE_P (TREE_TYPE (result)) - && SSA_NAME_PTR_INFO (result) - && ! SSA_NAME_IS_DEFAULT_DEF (result)) - { - if (! VN_INFO (result)->info.ptr_info) - VN_INFO (result)->info.ptr_info - = SSA_NAME_PTR_INFO (result); - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "clearing points-to info of "); - print_generic_expr (dump_file, result); - fprintf (dump_file, "\n"); - } - SSA_NAME_PTR_INFO (result) = NULL; - } } else { -- 2.30.2