Commit b43a2366 by Zdenek Dvorak Committed by Zdenek Dvorak

re PR tree-optimization/28364 (poor optimization choices when iterating over a…

re PR tree-optimization/28364 (poor optimization choices when iterating over a std::string (probably not c++-specific))

	PR tree-optimization/28364
	* tree-ssa-loop-ivopts.c (aff_combination_to_tree): Handle zero
	correctly.
	(fold_affine_expr): New function.
	(may_eliminate_iv): Use fold_affine_expr.

From-SVN: r116189
parent c58e8676
2006-08-16 Zdenek Dvorak <dvorakz@suse.cz>
PR tree-optimization/28364
* tree-ssa-loop-ivopts.c (aff_combination_to_tree): Handle zero
correctly.
(fold_affine_expr): New function.
(may_eliminate_iv): Use fold_affine_expr.
2006-08-16 Volker Reichelt <reichelt@igpm.rwth-aachen.de> 2006-08-16 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c/27489 PR c/27489
......
...@@ -2917,10 +2917,17 @@ aff_combination_to_tree (struct affine_tree_combination *comb) ...@@ -2917,10 +2917,17 @@ aff_combination_to_tree (struct affine_tree_combination *comb)
unsigned i; unsigned i;
unsigned HOST_WIDE_INT off, sgn; unsigned HOST_WIDE_INT off, sgn;
/* Handle the special case produced by get_computation_aff when
the type does not fit in HOST_WIDE_INT. */
if (comb->n == 0 && comb->offset == 0) if (comb->n == 0 && comb->offset == 0)
return fold_convert (type, expr); {
if (expr)
{
/* Handle the special case produced by get_computation_aff when
the type does not fit in HOST_WIDE_INT. */
return fold_convert (type, expr);
}
else
return build_int_cst (type, 0);
}
gcc_assert (comb->n == MAX_AFF_ELTS || comb->rest == NULL_TREE); gcc_assert (comb->n == MAX_AFF_ELTS || comb->rest == NULL_TREE);
...@@ -2943,6 +2950,21 @@ aff_combination_to_tree (struct affine_tree_combination *comb) ...@@ -2943,6 +2950,21 @@ aff_combination_to_tree (struct affine_tree_combination *comb)
comb->mask); comb->mask);
} }
/* Folds EXPR using the affine expressions framework. */
static tree
fold_affine_expr (tree expr)
{
tree type = TREE_TYPE (expr);
struct affine_tree_combination comb;
if (TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT)
return expr;
tree_to_aff_combination (expr, type, &comb);
return aff_combination_to_tree (&comb);
}
/* 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 a decomposed
form into AFF. Returns false if USE cannot be expressed using CAND. */ form into AFF. Returns false if USE cannot be expressed using CAND. */
...@@ -4029,7 +4051,7 @@ may_eliminate_iv (struct ivopts_data *data, ...@@ -4029,7 +4051,7 @@ may_eliminate_iv (struct ivopts_data *data,
fold_convert (wider_type, nit)))) fold_convert (wider_type, nit))))
return false; return false;
*bound = cand_value_at (loop, cand, use->stmt, nit); *bound = fold_affine_expr (cand_value_at (loop, cand, use->stmt, nit));
return true; return true;
} }
......
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