diff options
author | Zdenek Dvorak <dvorakz@suse.cz> | 2007-01-10 01:44:26 +0100 |
---|---|---|
committer | Zdenek Dvorak <rakdver@gcc.gnu.org> | 2007-01-10 00:44:26 +0000 |
commit | 7e2ac86c349ecfe90cc98f24230659136806fefa (patch) | |
tree | f1798b70409e7522ae71bb941b4d1af411b2db36 /gcc/tree-affine.c | |
parent | 92c25b55d49ef9ba4c273ec543ad23b684389123 (diff) | |
download | gcc-7e2ac86c349ecfe90cc98f24230659136806fefa.zip gcc-7e2ac86c349ecfe90cc98f24230659136806fefa.tar.gz gcc-7e2ac86c349ecfe90cc98f24230659136806fefa.tar.bz2 |
re PR middle-end/30322 (((-i-1) + i) +1) is turned into ~i + (i+1) and never into 0 on the tree level)
PR tree-optimization/30322
* tree-ssa-loop-ivopts.c (fold_affine_expr, iv_value): Removed.
(cand_value_at): Return the value as aff_tree.
(may_eliminate_iv): Convert the bound from aff_tree to tree.
* tree-affine.c (aff_combination_add_cst, aff_combination_add_product,
aff_combination_mult): New functions.
(aff_combination_add): Use aff_combination_add_cst.
(aff_combination_convert): Allow conversions to a wider type.
(tree_to_aff_combination): Handle BIT_NOT_EXPR.
* tree-affine.h (aff_combination_mult): Declare.
* gcc.dg/tree-ssa/loop-21.c: New test.
From-SVN: r120630
Diffstat (limited to 'gcc/tree-affine.c')
-rw-r--r-- | gcc/tree-affine.c | 89 |
1 files changed, 85 insertions, 4 deletions
diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index 762e82e..43b251d 100644 --- a/gcc/tree-affine.c +++ b/gcc/tree-affine.c @@ -180,6 +180,14 @@ aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale) comb->rest = elt; } +/* Adds CST to C. */ + +static void +aff_combination_add_cst (aff_tree *c, double_int cst) +{ + c->offset = double_int_ext_for_comb (double_int_add (c->offset, cst), c); +} + /* Adds COMB2 to COMB1. */ void @@ -187,9 +195,7 @@ aff_combination_add (aff_tree *comb1, aff_tree *comb2) { unsigned i; - comb1->offset - = double_int_ext_for_comb (double_int_add (comb1->offset, comb2->offset), - comb1); + aff_combination_add_cst (comb1, comb2->offset); for (i = 0; i < comb2->n; i++) aff_combination_add_elt (comb1, comb2->elts[i].val, comb2->elts[i].coef); if (comb2->rest) @@ -204,7 +210,13 @@ aff_combination_convert (aff_tree *comb, tree type) unsigned i, j; tree comb_type = comb->type; - gcc_assert (TYPE_PRECISION (type) <= TYPE_PRECISION (comb_type)); + if (TYPE_PRECISION (type) > TYPE_PRECISION (comb_type)) + { + tree val = fold_convert (type, aff_combination_to_tree (comb)); + tree_to_aff_combination (val, type, comb); + return; + } + comb->type = type; if (comb->rest) comb->rest = fold_convert (type, comb->rest); @@ -276,6 +288,13 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) aff_combination_scale (comb, double_int_minus_one); return; + case BIT_NOT_EXPR: + /* ~x = -x - 1 */ + tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb); + aff_combination_scale (comb, double_int_minus_one); + aff_combination_add_cst (comb, double_int_minus_one); + return; + case ADDR_EXPR: core = get_inner_reference (TREE_OPERAND (expr, 0), &bitsize, &bitpos, &toffset, &mode, &unsignedp, &volatilep, @@ -412,3 +431,65 @@ aff_combination_remove_elt (aff_tree *comb, unsigned m) comb->n++; } } + +/* Adds C * COEF * VAL to R. VAL may be NULL, in that case only + C * COEF is added to R. */ + + +static void +aff_combination_add_product (aff_tree *c, double_int coef, tree val, + aff_tree *r) +{ + unsigned i; + tree aval, type; + + for (i = 0; i < c->n; i++) + { + aval = c->elts[i].val; + if (val) + { + type = TREE_TYPE (aval); + aval = fold_build2 (MULT_EXPR, type, aval, + fold_convert (type, val)); + } + + aff_combination_add_elt (r, aval, + double_int_mul (coef, c->elts[i].coef)); + } + + if (c->rest) + { + aval = c->rest; + if (val) + { + type = TREE_TYPE (aval); + aval = fold_build2 (MULT_EXPR, type, aval, + fold_convert (type, val)); + } + + aff_combination_add_elt (r, aval, coef); + } + + if (val) + aff_combination_add_elt (r, val, + double_int_mul (coef, c->offset)); + else + aff_combination_add_cst (r, double_int_mul (coef, c->offset)); +} + +/* Multiplies C1 by C2, storing the result to R */ + +void +aff_combination_mult (aff_tree *c1, aff_tree *c2, aff_tree *r) +{ + unsigned i; + gcc_assert (TYPE_PRECISION (c1->type) == TYPE_PRECISION (c2->type)); + + aff_combination_zero (r, c1->type); + + for (i = 0; i < c2->n; i++) + aff_combination_add_product (c1, c2->elts[i].coef, c2->elts[i].val, r); + if (c2->rest) + aff_combination_add_product (c1, double_int_one, c2->rest, r); + aff_combination_add_product (c1, c2->offset, NULL, r); +} |