From: Richard Biener Date: Mon, 7 Apr 2014 14:03:55 +0000 (+0000) Subject: re PR tree-optimization/60766 (Wrong optimization with -O2) X-Git-Tag: basepoints/gcc-5~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d6adff07f12460e7c6de668c40d0fafabe737051;p=thirdparty%2Fgcc.git re PR tree-optimization/60766 (Wrong optimization with -O2) 2014-04-07 Richard Biener 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d3cde1e03bd1..b7743c71e7df 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2014-04-07 Richard Biener + + 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 PR c++/60731 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4b252901db3b..a75405d5414f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-04-07 Richard Biener + + PR tree-optimization/60766 + * gcc.dg/torture/pr60766.c: New testcase. + 2014-04-07 Jason Merrill * lib/gcc-dg.exp (dg-build-dso): New. diff --git a/gcc/testsuite/gcc.dg/torture/pr60766.c b/gcc/testsuite/gcc.dg/torture/pr60766.c new file mode 100644 index 000000000000..6f16e3b7408b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr60766.c @@ -0,0 +1,15 @@ +/* { 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(); +} diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 14ba20fce772..8bc4e8fc7913 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -4363,8 +4363,10 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter, tree steptype = type; if (POINTER_TYPE_P (type)) 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); aff_combination_convert (&nit, steptype); aff_combination_mult (&nit, &step, &delta); @@ -4372,6 +4374,8 @@ cand_value_at (struct loop *loop, struct iv_cand *cand, gimple at, tree niter, aff_combination_add (&delta, &step); tree_to_aff_combination (iv->base, type, val); + if (!POINTER_TYPE_P (type)) + aff_combination_convert (val, steptype); aff_combination_add (val, &delta); } @@ -4750,7 +4754,8 @@ may_eliminate_iv (struct ivopts_data *data, 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); /* It is unlikely that computing the number of iterations using division