Commit 98aaa1a6 by Bin Cheng Committed by Bin Cheng

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
parent 5900c710
2019-05-14 Bin Cheng <bin.cheng@linux.alibaba.com>
* 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 <nathan@acm.org> 2019-05-13 Nathan Sidwell <nathan@acm.org>
* gcc.c (execute): Simplify cond-expr into if. Reformat comment. * gcc.c (execute): Simplify cond-expr into if. Reformat comment.
......
...@@ -418,7 +418,7 @@ static bool legal_cast_p_1 (tree, tree); ...@@ -418,7 +418,7 @@ static bool legal_cast_p_1 (tree, tree);
static slsr_cand_t static slsr_cand_t
lookup_cand (cand_idx idx) lookup_cand (cand_idx idx)
{ {
return cand_vec[idx - 1]; return cand_vec[idx];
} }
/* Helper for hashing a candidate chain header. */ /* Helper for hashing a candidate chain header. */
...@@ -688,7 +688,7 @@ alloc_cand_and_find_basis (enum cand_kind kind, gimple *gs, tree base, ...@@ -688,7 +688,7 @@ alloc_cand_and_find_basis (enum cand_kind kind, gimple *gs, tree base,
c->cand_type = ctype; c->cand_type = ctype;
c->stride_type = stype; c->stride_type = stype;
c->kind = kind; c->kind = kind;
c->cand_num = cand_vec.length () + 1; c->cand_num = cand_vec.length ();
c->next_interp = 0; c->next_interp = 0;
c->first_interp = c->cand_num; c->first_interp = c->cand_num;
c->dependent = 0; c->dependent = 0;
...@@ -933,10 +933,7 @@ backtrace_base_for_ref (tree *pbase) ...@@ -933,10 +933,7 @@ backtrace_base_for_ref (tree *pbase)
return base_cand->index; return base_cand->index;
} }
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
return 0; return 0;
...@@ -1124,10 +1121,7 @@ create_mul_ssa_cand (gimple *gs, tree base_in, tree stride_in, bool speed) ...@@ -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)); + stmt_cost (base_cand->cand_stmt, speed));
} }
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
if (!base) if (!base)
...@@ -1214,10 +1208,7 @@ create_mul_imm_cand (gimple *gs, tree base_in, tree stride_in, bool speed) ...@@ -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)); + stmt_cost (base_cand->cand_stmt, speed));
} }
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
if (!base) if (!base)
...@@ -1320,10 +1311,7 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in, ...@@ -1320,10 +1311,7 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in,
+ stmt_cost (addend_cand->cand_stmt, speed)); + stmt_cost (addend_cand->cand_stmt, speed));
} }
if (addend_cand->next_interp)
addend_cand = lookup_cand (addend_cand->next_interp); addend_cand = lookup_cand (addend_cand->next_interp);
else
addend_cand = NULL;
} }
while (base_cand && !base && base_cand->kind != CAND_PHI) while (base_cand && !base && base_cand->kind != CAND_PHI)
...@@ -1372,17 +1360,11 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in, ...@@ -1372,17 +1360,11 @@ create_add_ssa_cand (gimple *gs, tree base_in, tree addend_in,
+ stmt_cost (subtrahend_cand->cand_stmt, speed)); + stmt_cost (subtrahend_cand->cand_stmt, speed));
} }
if (subtrahend_cand->next_interp)
subtrahend_cand = lookup_cand (subtrahend_cand->next_interp); subtrahend_cand = lookup_cand (subtrahend_cand->next_interp);
else
subtrahend_cand = NULL;
} }
} }
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
if (!base) if (!base)
...@@ -1446,10 +1428,7 @@ create_add_imm_cand (gimple *gs, tree base_in, const widest_int &index_in, ...@@ -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)); + stmt_cost (base_cand->cand_stmt, speed));
} }
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
if (!base) if (!base)
...@@ -1652,10 +1631,7 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed) ...@@ -1652,10 +1631,7 @@ slsr_process_cast (gimple *gs, tree rhs1, bool speed)
if (first_cand != c) if (first_cand != c)
c->first_interp = first_cand->cand_num; c->first_interp = first_cand->cand_num;
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
} }
else else
...@@ -1719,10 +1695,7 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed) ...@@ -1719,10 +1695,7 @@ slsr_process_copy (gimple *gs, tree rhs1, bool speed)
if (first_cand != c) if (first_cand != c)
c->first_interp = first_cand->cand_num; c->first_interp = first_cand->cand_num;
if (base_cand->next_interp)
base_cand = lookup_cand (base_cand->next_interp); base_cand = lookup_cand (base_cand->next_interp);
else
base_cand = NULL;
} }
} }
else else
...@@ -1933,6 +1906,7 @@ dump_cand_vec (void) ...@@ -1933,6 +1906,7 @@ dump_cand_vec (void)
fprintf (dump_file, "\nStrength reduction candidate vector:\n\n"); fprintf (dump_file, "\nStrength reduction candidate vector:\n\n");
FOR_EACH_VEC_ELT (cand_vec, i, c) FOR_EACH_VEC_ELT (cand_vec, i, c)
if (c != NULL)
dump_candidate (c); dump_candidate (c);
} }
...@@ -2181,7 +2155,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) ...@@ -2181,7 +2155,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump)
while (cc) while (cc)
{ {
cc->cand_stmt = copy_stmt; 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)) if (dump_file && (dump_flags & TDF_DETAILS))
stmt_to_print = copy_stmt; stmt_to_print = copy_stmt;
...@@ -2214,7 +2188,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump) ...@@ -2214,7 +2188,7 @@ replace_mult_candidate (slsr_cand_t c, tree basis_name, widest_int bump)
while (cc) while (cc)
{ {
cc->cand_stmt = gsi_stmt (gsi); 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)) if (dump_file && (dump_flags & TDF_DETAILS))
stmt_to_print = gsi_stmt (gsi); 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, ...@@ -3654,7 +3628,7 @@ replace_rhs_if_not_dup (enum tree_code new_code, tree new_rhs1, tree new_rhs2,
while (cc) while (cc)
{ {
cc->cand_stmt = gsi_stmt (gsi); 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)) if (dump_file && (dump_flags & TDF_DETAILS))
...@@ -3770,7 +3744,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) ...@@ -3770,7 +3744,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name)
while (cc) while (cc)
{ {
cc->cand_stmt = gsi_stmt (gsi); 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)) if (dump_file && (dump_flags & TDF_DETAILS))
...@@ -3796,7 +3770,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) ...@@ -3796,7 +3770,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name)
while (cc) while (cc)
{ {
cc->cand_stmt = copy_stmt; 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)) if (dump_file && (dump_flags & TDF_DETAILS))
...@@ -3812,7 +3786,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name) ...@@ -3812,7 +3786,7 @@ replace_one_candidate (slsr_cand_t c, unsigned i, tree basis_name)
while (cc) while (cc)
{ {
cc->cand_stmt = cast_stmt; 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)) if (dump_file && (dump_flags & TDF_DETAILS))
...@@ -3902,8 +3876,10 @@ analyze_candidates_and_replace (void) ...@@ -3902,8 +3876,10 @@ analyze_candidates_and_replace (void)
/* Each candidate that has a null basis and a non-null /* Each candidate that has a null basis and a non-null
dependent is the root of a tree of related statements. dependent is the root of a tree of related statements.
Analyze each tree to determine a subset of those Analyze each tree to determine a subset of those
statements that can be replaced with maximum benefit. */ statements that can be replaced with maximum benefit.
FOR_EACH_VEC_ELT (cand_vec, i, c)
Note the first NULL element is skipped. */
FOR_EACH_VEC_ELT_FROM (cand_vec, i, c, 1)
{ {
slsr_cand_t first_dep; slsr_cand_t first_dep;
...@@ -4010,8 +3986,9 @@ pass_strength_reduction::execute (function *fun) ...@@ -4010,8 +3986,9 @@ pass_strength_reduction::execute (function *fun)
/* Create the obstack where candidates will reside. */ /* Create the obstack where candidates will reside. */
gcc_obstack_init (&cand_obstack); 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.create (128);
cand_vec.safe_push (NULL);
/* Allocate the mapping from statements to candidate indices. */ /* Allocate the mapping from statements to candidate indices. */
stmt_cand_map = new hash_map<gimple *, slsr_cand_t>; stmt_cand_map = new hash_map<gimple *, slsr_cand_t>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment