From: Bill Schmidt Date: Fri, 1 Jun 2018 13:00:57 +0000 (+0000) Subject: backport: [multiple changes] X-Git-Tag: releases/gcc-6.5.0~294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6f3beab9d27d8c066724496cc2a9fb91f2229aa;p=thirdparty%2Fgcc.git backport: [multiple changes] 2018-06-01 Bill Schmidt PR tree-optimization/85712 Backport from mainline: 2018-05-23 Bill Schmidt PR tree-optimization/85712 * gimple-ssa-strength-reduction.c (struct slsr_cand_d): Add first_interp field. (alloc_cand_and_find_basis): Initialize first_interp field. (slsr_process_mul): Modify first_interp field. (slsr_process_add): Likewise. (slsr_process_cast): Modify first_interp field for each new interpretation. (slsr_process_copy): Likewise. (dump_candidate): Dump first_interp field. (replace_mult_candidate): Process all interpretations, not just subsequent ones. (replace_rhs_if_not_dup): Likewise. (replace_one_candidate): Likewise. Backport from mainline: 2018-05-25 Bill Schmidt PR tree-optimization/85712 * gimple-ssa-strength-reduction.c (replace_one_candidate): Skip if this candidate has already been replaced in-situ by a copy. From-SVN: r261067 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6c0d2d4e4293..62fb98588731 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,31 @@ +2018-06-01 Bill Schmidt + + PR tree-optimization/85712 + Backport from mainline: + 2018-05-23 Bill Schmidt + + PR tree-optimization/85712 + * gimple-ssa-strength-reduction.c (struct slsr_cand_d): Add + first_interp field. + (alloc_cand_and_find_basis): Initialize first_interp field. + (slsr_process_mul): Modify first_interp field. + (slsr_process_add): Likewise. + (slsr_process_cast): Modify first_interp field for each new + interpretation. + (slsr_process_copy): Likewise. + (dump_candidate): Dump first_interp field. + (replace_mult_candidate): Process all interpretations, not just + subsequent ones. + (replace_rhs_if_not_dup): Likewise. + (replace_one_candidate): Likewise. + + Backport from mainline: + 2018-05-25 Bill Schmidt + + PR tree-optimization/85712 + * gimple-ssa-strength-reduction.c (replace_one_candidate): Skip if + this candidate has already been replaced in-situ by a copy. + 2018-05-24 Uros Bizjak * config/i386/sse.md (cvtusi264): diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c index ae2a3b35cd9b..46bce1c4b0ef 100644 --- a/gcc/gimple-ssa-strength-reduction.c +++ b/gcc/gimple-ssa-strength-reduction.c @@ -258,6 +258,10 @@ struct slsr_cand_d of a statement. */ cand_idx next_interp; + /* Index of the first candidate record in a chain for the same + statement. */ + cand_idx first_interp; + /* Index of the basis statement S0, if any, in the candidate vector. */ cand_idx basis; @@ -633,6 +637,7 @@ alloc_cand_and_find_basis (enum cand_kind kind, gimple *gs, tree base, c->kind = kind; c->cand_num = cand_vec.length () + 1; c->next_interp = 0; + c->first_interp = c->cand_num; c->dependent = 0; c->sibling = 0; c->def_phi = kind == CAND_MULT ? find_phi_def (base) : 0; @@ -1198,6 +1203,7 @@ slsr_process_mul (gimple *gs, tree rhs1, tree rhs2, bool speed) is the stride and RHS2 is the base expression. */ c2 = create_mul_ssa_cand (gs, rhs2, rhs1, speed); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } else { @@ -1425,7 +1431,10 @@ slsr_process_add (gimple *gs, tree rhs1, tree rhs2, bool speed) { c2 = create_add_ssa_cand (gs, rhs2, rhs1, false, speed); if (c) - c->next_interp = c2->cand_num; + { + c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; + } else add_cand_for_stmt (gs, c2); } @@ -1551,6 +1560,8 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed) if (base_cand && base_cand->kind != CAND_PHI) { + slsr_cand_t first_cand = NULL; + while (base_cand) { /* Propagate all data from the base candidate except the type, @@ -1564,6 +1575,12 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed) base_cand->base_expr, base_cand->index, base_cand->stride, ctype, savings); + if (!first_cand) + first_cand = c; + + if (first_cand != c) + c->first_interp = first_cand->cand_num; + if (base_cand->next_interp) base_cand = lookup_cand (base_cand->next_interp); else @@ -1586,6 +1603,7 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed) c2 = alloc_cand_and_find_basis (CAND_MULT, gs, rhs1, 0, integer_one_node, ctype, 0); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } /* Add the first (or only) interpretation to the statement-candidate @@ -1610,6 +1628,8 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed) if (base_cand && base_cand->kind != CAND_PHI) { + slsr_cand_t first_cand = NULL; + while (base_cand) { /* Propagate all data from the base candidate. */ @@ -1621,6 +1641,12 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed) base_cand->base_expr, base_cand->index, base_cand->stride, base_cand->cand_type, savings); + if (!first_cand) + first_cand = c; + + if (first_cand != c) + c->first_interp = first_cand->cand_num; + if (base_cand->next_interp) base_cand = lookup_cand (base_cand->next_interp); else @@ -1643,6 +1669,7 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed) c2 = alloc_cand_and_find_basis (CAND_MULT, gs, rhs1, 0, integer_one_node, TREE_TYPE (rhs1), 0); c->next_interp = c2->cand_num; + c2->first_interp = c->cand_num; } /* Add the first (or only) interpretation to the statement-candidate @@ -1796,8 +1823,9 @@ dump_candidate (slsr_cand_t c) print_generic_expr (dump_file, c->cand_type, 0); fprintf (dump_file, "\n basis: %d dependent: %d sibling: %d\n", c->basis, c->dependent, c->sibling); - fprintf (dump_file, " next-interp: %d dead-savings: %d\n", - c->next_interp, c->dead_savings); + fprintf (dump_file, + " next-interp: %d first-interp: %d dead-savings: %d\n", + c->next_interp, c->first_interp, c->dead_savings); if (c->def_phi) fprintf (dump_file, " phi: %d\n", c->def_phi); fputs ("\n", dump_file); @@ -2055,9 +2083,14 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) tree lhs = gimple_assign_lhs (c->cand_stmt); gassign *copy_stmt = gimple_build_assign (lhs, basis_name); gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (copy_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, copy_stmt, false); - c->cand_stmt = copy_stmt; + while (cc) + { + cc->cand_stmt = copy_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = copy_stmt; } @@ -2083,10 +2116,15 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) else { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, code, basis_name, bump_tree); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); + while (cc) + { + cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = gsi_stmt (gsi); } @@ -3296,10 +3334,14 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2, || !operand_equal_p (new_rhs2, old_rhs1, 0)))) { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, new_code, new_rhs1, new_rhs2); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); - + while (cc) + { + cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) return gsi_stmt (gsi); } @@ -3330,6 +3372,11 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) orig_rhs2 = gimple_assign_rhs2 (c->cand_stmt); cand_incr = cand_increment (c); + /* If orig_rhs2 is NULL, we have already replaced this in situ with + a copy statement under another interpretation. */ + if (!orig_rhs2) + return; + if (dump_file && (dump_flags & TDF_DETAILS)) { fputs ("Replacing: ", dump_file); @@ -3402,10 +3449,14 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) || !operand_equal_p (rhs2, orig_rhs2, 0)) { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_assign_set_rhs_with_ops (&gsi, MINUS_EXPR, basis_name, rhs2); update_stmt (gsi_stmt (gsi)); - c->cand_stmt = gsi_stmt (gsi); - + while (cc) + { + cc->cand_stmt = gsi_stmt (gsi); + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = gsi_stmt (gsi); } @@ -3423,10 +3474,14 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) { gassign *copy_stmt = gimple_build_assign (lhs, basis_name); gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (copy_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, copy_stmt, false); - c->cand_stmt = copy_stmt; - + while (cc) + { + cc->cand_stmt = copy_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = copy_stmt; } @@ -3434,10 +3489,14 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) { gimple_stmt_iterator gsi = gsi_for_stmt (c->cand_stmt); gassign *cast_stmt = gimple_build_assign (lhs, NOP_EXPR, basis_name); + slsr_cand_t cc = lookup_cand (c->first_interp); gimple_set_location (cast_stmt, gimple_location (c->cand_stmt)); gsi_replace (&gsi, cast_stmt, false); - c->cand_stmt = cast_stmt; - + while (cc) + { + cc->cand_stmt = cast_stmt; + cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = cast_stmt; }