From: Bin Cheng Date: Tue, 14 May 2019 01:18:53 +0000 (+0000) Subject: gimple-ssa-strength-reduction.c (lookup_cand): Adjust index by 1. X-Git-Tag: misc/cutover-git~5592 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98aaa1a633cf3a79fa281a383c12fc45b313e824;p=thirdparty%2Fgcc.git gimple-ssa-strength-reduction.c (lookup_cand): Adjust index by 1. * gimple-ssa-strength-reduction.c (lookup_cand): Adjust index by 1. (alloc_cand_and_find_basis): Ditto. (backtrace_base_for_ref, create_mul_ssa_cand): Remove if-then-else. (create_mul_imm_cand, create_add_ssa_cand): Ditto. (create_add_imm_cand, slsr_process_cast): Ditto. (slsr_process_copy, replace_mult_candidate): Ditto. (replace_rhs_if_not_dup, replace_one_candidate): Ditto. (dump_cand_vec, analyze_candidates_and_replace): Skip NULL element. (pass_strength_reduction::execute): Init the first NULL element. From-SVN: r271145 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0baa99366a59..0985651503a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2019-05-14 Bin Cheng + + * gimple-ssa-strength-reduction.c (lookup_cand): Adjust index by 1. + (alloc_cand_and_find_basis): Ditto. + (backtrace_base_for_ref, create_mul_ssa_cand): Remove if-then-else. + (create_mul_imm_cand, create_add_ssa_cand): Ditto. + (create_add_imm_cand, slsr_process_cast): Ditto. + (slsr_process_copy, replace_mult_candidate): Ditto. + (replace_rhs_if_not_dup, replace_one_candidate): Ditto. + (dump_cand_vec, analyze_candidates_and_replace): Skip NULL element. + (pass_strength_reduction::execute): Init the first NULL element. + 2019-05-13 Nathan Sidwell * gcc.c (execute): Simplify cond-expr into if. Reformat comment. diff --git a/gcc/gimple-ssa-strength-reduction.c b/gcc/gimple-ssa-strength-reduction.c index 937a87761c89..bfda44a10288 100644 --- a/gcc/gimple-ssa-strength-reduction.c +++ b/gcc/gimple-ssa-strength-reduction.c @@ -418,7 +418,7 @@ static bool legal_cast_p_1 (tree, tree); static slsr_cand_t lookup_cand (cand_idx idx) { - return cand_vec[idx - 1]; + return cand_vec[idx]; } /* Helper for hashing a candidate chain header. */ @@ -688,7 +688,7 @@ alloc_cand_and_find_basis (enum cand_kind kind, gimple *gs, tree base, c->cand_type = ctype; c->stride_type = stype; c->kind = kind; - c->cand_num = cand_vec.length () + 1; + c->cand_num = cand_vec.length (); c->next_interp = 0; c->first_interp = c->cand_num; c->dependent = 0; @@ -933,10 +933,7 @@ backtrace_base_for_ref (tree *pbase) return base_cand->index; } - if (base_cand->next_interp) - base_cand = lookup_cand (base_cand->next_interp); - else - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } return 0; @@ -1124,10 +1121,7 @@ create_mul_ssa_cand (gimple *gs, tree base_in, tree stride_in, bool speed) + stmt_cost (base_cand->cand_stmt, speed)); } - if (base_cand->next_interp) - base_cand = lookup_cand (base_cand->next_interp); - else - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } if (!base) @@ -1214,10 +1208,7 @@ create_mul_imm_cand (gimple *gs, tree base_in, tree stride_in, bool speed) + stmt_cost (base_cand->cand_stmt, speed)); } - if (base_cand->next_interp) - base_cand = lookup_cand (base_cand->next_interp); - else - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } if (!base) @@ -1320,10 +1311,7 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in, + stmt_cost (addend_cand->cand_stmt, speed)); } - if (addend_cand->next_interp) - addend_cand = lookup_cand (addend_cand->next_interp); - else - addend_cand = NULL; + addend_cand = lookup_cand (addend_cand->next_interp); } while (base_cand && !base && base_cand->kind != CAND_PHI) @@ -1371,18 +1359,12 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in, savings = (subtrahend_cand->dead_savings + stmt_cost (subtrahend_cand->cand_stmt, speed)); } - - if (subtrahend_cand->next_interp) - subtrahend_cand = lookup_cand (subtrahend_cand->next_interp); - else - subtrahend_cand = NULL; + + subtrahend_cand = lookup_cand (subtrahend_cand->next_interp); } } - if (base_cand->next_interp) - base_cand = lookup_cand (base_cand->next_interp); - else - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } if (!base) @@ -1446,10 +1428,7 @@ create_add_imm_cand (gimple *gs, tree base_in, const widest_int &index_in, + stmt_cost (base_cand->cand_stmt, speed)); } - if (base_cand->next_interp) - base_cand = lookup_cand (base_cand->next_interp); - else - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } if (!base) @@ -1652,10 +1631,7 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed) 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 - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } } else @@ -1719,10 +1695,7 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed) 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 - base_cand = NULL; + base_cand = lookup_cand (base_cand->next_interp); } } else @@ -1933,7 +1906,8 @@ dump_cand_vec (void) fprintf (dump_file, "\nStrength reduction candidate vector:\n\n"); FOR_EACH_VEC_ELT (cand_vec, i, c) - dump_candidate (c); + if (c != NULL) + dump_candidate (c); } /* Callback used to dump the candidate chains hash table. */ @@ -2181,7 +2155,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) while (cc) { cc->cand_stmt = copy_stmt; - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = copy_stmt; @@ -2214,7 +2188,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) while (cc) { cc->cand_stmt = gsi_stmt (gsi); - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) stmt_to_print = gsi_stmt (gsi); @@ -3654,7 +3628,7 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2, while (cc) { cc->cand_stmt = gsi_stmt (gsi); - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3770,7 +3744,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) while (cc) { cc->cand_stmt = gsi_stmt (gsi); - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3796,7 +3770,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) while (cc) { cc->cand_stmt = copy_stmt; - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3812,7 +3786,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) while (cc) { cc->cand_stmt = cast_stmt; - cc = cc->next_interp ? lookup_cand (cc->next_interp) : NULL; + cc = lookup_cand (cc->next_interp); } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3902,8 +3876,10 @@ analyze_candidates_and_replace (void) /* Each candidate that has a null basis and a non-null dependent is the root of a tree of related statements. Analyze each tree to determine a subset of those - statements that can be replaced with maximum benefit. */ - FOR_EACH_VEC_ELT (cand_vec, i, c) + statements that can be replaced with maximum benefit. + + Note the first NULL element is skipped. */ + FOR_EACH_VEC_ELT_FROM (cand_vec, i, c, 1) { slsr_cand_t first_dep; @@ -4010,8 +3986,9 @@ pass_strength_reduction::execute (function *fun) /* Create the obstack where candidates will reside. */ gcc_obstack_init (&cand_obstack); - /* Allocate the candidate vector. */ + /* Allocate the candidate vector and initialize the first NULL element. */ cand_vec.create (128); + cand_vec.safe_push (NULL); /* Allocate the mapping from statements to candidate indices. */ stmt_cand_map = new hash_map;