Commit d6adff07 by Richard Biener Committed by Richard Biener

re PR tree-optimization/60766 (Wrong optimization with -O2)

2014-04-07  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/60766
	* tree-ssa-loop-ivopts.c (cand_value_at): Compute in an
	unsigned type.
	(may_eliminate_iv): Convert cand_value_at result to desired
	type.

	* gcc.dg/torture/pr60766.c: New testcase.

From-SVN: r209190
parent 9d7aea5f
2014-04-07 Richard Biener <rguenther@suse.de>
PR tree-optimization/60766
* tree-ssa-loop-ivopts.c (cand_value_at): Compute in an
unsigned type.
(may_eliminate_iv): Convert cand_value_at result to desired
type.
2014-04-07 Jason Merrill <jason@redhat.com> 2014-04-07 Jason Merrill <jason@redhat.com>
PR c++/60731 PR c++/60731
......
2014-04-07 Richard Biener <rguenther@suse.de>
PR tree-optimization/60766
* gcc.dg/torture/pr60766.c: New testcase.
2014-04-07 Jason Merrill <jason@redhat.com> 2014-04-07 Jason Merrill <jason@redhat.com>
* lib/gcc-dg.exp (dg-build-dso): New. * lib/gcc-dg.exp (dg-build-dso): New.
......
/* { dg-do run } */
int m = 9;
int main()
{
int n, x;
n = m;
for (x = 0; x <= n; x++)
if (n == x + (x + 1) + (x + 2))
return 0;
__builtin_abort();
}
...@@ -4363,8 +4363,10 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter, ...@@ -4363,8 +4363,10 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter,
tree steptype = type; tree steptype = type;
if (POINTER_TYPE_P (type)) if (POINTER_TYPE_P (type))
steptype = sizetype; steptype = sizetype;
steptype = unsigned_type_for (type);
tree_to_aff_combination (iv->step, steptype, &step); tree_to_aff_combination (iv->step, TREE_TYPE (iv->step), &step);
aff_combination_convert (&step, steptype);
tree_to_aff_combination (niter, TREE_TYPE (niter), &nit); tree_to_aff_combination (niter, TREE_TYPE (niter), &nit);
aff_combination_convert (&nit, steptype); aff_combination_convert (&nit, steptype);
aff_combination_mult (&nit, &step, &delta); aff_combination_mult (&nit, &step, &delta);
...@@ -4372,6 +4374,8 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter, ...@@ -4372,6 +4374,8 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter,
aff_combination_add (&delta, &step); aff_combination_add (&delta, &step);
tree_to_aff_combination (iv->base, type, val); tree_to_aff_combination (iv->base, type, val);
if (!POINTER_TYPE_P (type))
aff_combination_convert (val, steptype);
aff_combination_add (val, &delta); aff_combination_add (val, &delta);
} }
...@@ -4750,7 +4754,8 @@ may_eliminate_iv (struct ivopts_data *data, ...@@ -4750,7 +4754,8 @@ may_eliminate_iv (struct ivopts_data *data,
cand_value_at (loop, cand, use->stmt, desc->niter, &bnd); cand_value_at (loop, cand, use->stmt, desc->niter, &bnd);
*bound = aff_combination_to_tree (&bnd); *bound = fold_convert (TREE_TYPE (cand->iv->base),
aff_combination_to_tree (&bnd));
*comp = iv_elimination_compare (data, use); *comp = iv_elimination_compare (data, use);
/* It is unlikely that computing the number of iterations using division /* It is unlikely that computing the number of iterations using division
......
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