Commit db61fc7a by Bin Cheng Committed by Bin Cheng

tree-ssa-loop-ivopts.c (get_computation_aff_1): New.

	* tree-ssa-loop-ivopts.c (get_computation_aff_1): New.
	(get_computation_aff): Reorder parameters.  Use get_computation_aff_1.
	(get_computation_at, rewrite_use_address): Update use of
	get_computation_aff.

From-SVN: r247518
parent c7da0e81
2017-05-02 Bin Cheng <bin.cheng@arm.com> 2017-05-02 Bin Cheng <bin.cheng@arm.com>
* tree-ssa-loop-ivopts.c (get_computation_aff_1): New.
(get_computation_aff): Reorder parameters. Use get_computation_aff_1.
(get_computation_at, rewrite_use_address): Update use of
get_computation_aff.
2017-05-02 Bin Cheng <bin.cheng@arm.com>
* tree-ssa-loop-ivopts.c (get_computation_at): Reorder parameters. * tree-ssa-loop-ivopts.c (get_computation_at): Reorder parameters.
(get_computation): Delete. (get_computation): Delete.
(get_computation_cost): Implement like get_computation_cost_at. (get_computation_cost): Implement like get_computation_cost_at.
......
...@@ -3711,29 +3711,26 @@ determine_common_wider_type (tree *a, tree *b) ...@@ -3711,29 +3711,26 @@ determine_common_wider_type (tree *a, tree *b)
} }
/* Determines the expression by that USE is expressed from induction variable /* Determines the expression by that USE is expressed from induction variable
CAND at statement AT in LOOP. The expression is stored in a decomposed CAND at statement AT in LOOP. The expression is stored in two parts in a
form into AFF. Returns false if USE cannot be expressed using CAND. */ decomposed form. The invariant part is stored in AFF_INV; while variant
part in AFF_VAR. Store ratio of CAND.step over USE.step in PRAT if it's
non-null. Returns false if USE cannot be expressed using CAND. */
static bool static bool
get_computation_aff (struct loop *loop, get_computation_aff_1 (struct loop *loop, gimple *at, struct iv_use *use,
struct iv_use *use, struct iv_cand *cand, gimple *at, struct iv_cand *cand, struct aff_tree *aff_inv,
struct aff_tree *aff) struct aff_tree *aff_var, widest_int *prat = NULL)
{ {
tree ubase = use->iv->base; tree ubase = use->iv->base, ustep = use->iv->step;
tree ustep = use->iv->step; tree cbase = cand->iv->base, cstep = cand->iv->step;
tree cbase = cand->iv->base; tree common_type, uutype, var, cstep_common;
tree cstep = cand->iv->step, cstep_common;
tree utype = TREE_TYPE (ubase), ctype = TREE_TYPE (cbase); tree utype = TREE_TYPE (ubase), ctype = TREE_TYPE (cbase);
tree common_type, var; aff_tree aff_cbase;
tree uutype;
aff_tree cbase_aff, var_aff;
widest_int rat; widest_int rat;
/* We must have a precision to express the values of use. */
if (TYPE_PRECISION (utype) > TYPE_PRECISION (ctype)) if (TYPE_PRECISION (utype) > TYPE_PRECISION (ctype))
{ return false;
/* We do not have a precision to express the values of use. */
return false;
}
var = var_at_stmt (loop, cand, at); var = var_at_stmt (loop, cand, at);
uutype = unsigned_type_for (utype); uutype = unsigned_type_for (utype);
...@@ -3763,8 +3760,8 @@ get_computation_aff (struct loop *loop, ...@@ -3763,8 +3760,8 @@ get_computation_aff (struct loop *loop,
cstep = inner_step; cstep = inner_step;
} }
} }
cstep = fold_convert (uutype, cstep);
cbase = fold_convert (uutype, cbase); cbase = fold_convert (uutype, cbase);
cstep = fold_convert (uutype, cstep);
var = fold_convert (uutype, var); var = fold_convert (uutype, var);
} }
...@@ -3783,6 +3780,9 @@ get_computation_aff (struct loop *loop, ...@@ -3783,6 +3780,9 @@ get_computation_aff (struct loop *loop,
else if (!constant_multiple_of (ustep, cstep, &rat)) else if (!constant_multiple_of (ustep, cstep, &rat))
return false; return false;
if (prat)
*prat = rat;
/* In case both UBASE and CBASE are shortened to UUTYPE from some common /* In case both UBASE and CBASE are shortened to UUTYPE from some common
type, we achieve better folding by computing their difference in this type, we achieve better folding by computing their difference in this
wider type, and cast the result to UUTYPE. We do not need to worry about wider type, and cast the result to UUTYPE. We do not need to worry about
...@@ -3791,9 +3791,9 @@ get_computation_aff (struct loop *loop, ...@@ -3791,9 +3791,9 @@ get_computation_aff (struct loop *loop,
common_type = determine_common_wider_type (&ubase, &cbase); common_type = determine_common_wider_type (&ubase, &cbase);
/* use = ubase - ratio * cbase + ratio * var. */ /* use = ubase - ratio * cbase + ratio * var. */
tree_to_aff_combination (ubase, common_type, aff); tree_to_aff_combination (ubase, common_type, aff_inv);
tree_to_aff_combination (cbase, common_type, &cbase_aff); tree_to_aff_combination (cbase, common_type, &aff_cbase);
tree_to_aff_combination (var, uutype, &var_aff); tree_to_aff_combination (var, uutype, aff_var);
/* We need to shift the value if we are after the increment. */ /* We need to shift the value if we are after the increment. */
if (stmt_after_increment (loop, cand, at)) if (stmt_after_increment (loop, cand, at))
...@@ -3806,17 +3806,32 @@ get_computation_aff (struct loop *loop, ...@@ -3806,17 +3806,32 @@ get_computation_aff (struct loop *loop,
cstep_common = cstep; cstep_common = cstep;
tree_to_aff_combination (cstep_common, common_type, &cstep_aff); tree_to_aff_combination (cstep_common, common_type, &cstep_aff);
aff_combination_add (&cbase_aff, &cstep_aff); aff_combination_add (&aff_cbase, &cstep_aff);
} }
aff_combination_scale (&cbase_aff, -rat); aff_combination_scale (&aff_cbase, -rat);
aff_combination_add (aff, &cbase_aff); aff_combination_add (aff_inv, &aff_cbase);
if (common_type != uutype) if (common_type != uutype)
aff_combination_convert (aff, uutype); aff_combination_convert (aff_inv, uutype);
aff_combination_scale (&var_aff, rat); aff_combination_scale (aff_var, rat);
aff_combination_add (aff, &var_aff); return true;
}
/* Determines the expression by that USE is expressed from induction variable
CAND at statement AT in LOOP. The expression is stored in a decomposed
form into AFF. Returns false if USE cannot be expressed using CAND. */
static bool
get_computation_aff (struct loop *loop, gimple *at, struct iv_use *use,
struct iv_cand *cand, struct aff_tree *aff)
{
aff_tree aff_var;
if (!get_computation_aff_1 (loop, at, use, cand, aff, &aff_var))
return false;
aff_combination_add (aff, &aff_var);
return true; return true;
} }
...@@ -3852,7 +3867,7 @@ get_computation_at (struct loop *loop, gimple *at, ...@@ -3852,7 +3867,7 @@ get_computation_at (struct loop *loop, gimple *at,
aff_tree aff; aff_tree aff;
tree type = get_use_type (use); tree type = get_use_type (use);
if (!get_computation_aff (loop, use, cand, at, &aff)) if (!get_computation_aff (loop, at, use, cand, &aff))
return NULL_TREE; return NULL_TREE;
unshare_aff_combination (&aff); unshare_aff_combination (&aff);
return fold_convert (type, aff_combination_to_tree (&aff)); return fold_convert (type, aff_combination_to_tree (&aff));
...@@ -7336,7 +7351,7 @@ rewrite_use_address (struct ivopts_data *data, ...@@ -7336,7 +7351,7 @@ rewrite_use_address (struct ivopts_data *data,
bool ok; bool ok;
adjust_iv_update_pos (cand, use); adjust_iv_update_pos (cand, use);
ok = get_computation_aff (data->current_loop, use, cand, use->stmt, &aff); ok = get_computation_aff (data->current_loop, use->stmt, use, cand, &aff);
gcc_assert (ok); gcc_assert (ok);
unshare_aff_combination (&aff); unshare_aff_combination (&aff);
......
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