aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-ivopts.c
diff options
context:
space:
mode:
authorZdenek Dvorak <dvorakz@suse.cz>2007-01-10 01:44:26 +0100
committerZdenek Dvorak <rakdver@gcc.gnu.org>2007-01-10 00:44:26 +0000
commit7e2ac86c349ecfe90cc98f24230659136806fefa (patch)
treef1798b70409e7522ae71bb941b4d1af411b2db36 /gcc/tree-ssa-loop-ivopts.c
parent92c25b55d49ef9ba4c273ec543ad23b684389123 (diff)
downloadgcc-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-ssa-loop-ivopts.c')
-rw-r--r--gcc/tree-ssa-loop-ivopts.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 411cad2..a11165d 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -2565,21 +2565,6 @@ constant_multiple_of (tree top, tree bot, double_int *mul)
}
}
-/* 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);
-}
-
/* If A is (TYPE) BA and B is (TYPE) BB, and the types of BA and BB have the
same precision that is at least as wide as the precision of TYPE, stores
BA to A and BB to B, and returns the type of BA. Otherwise, returns the
@@ -3557,32 +3542,26 @@ determine_use_iv_cost_address (struct ivopts_data *data,
return cost != INFTY;
}
-/* Computes value of induction variable IV in iteration NITER. */
+/* Computes value of candidate CAND at position AT in iteration NITER, and
+ stores it to VAL. */
-static tree
-iv_value (struct iv *iv, tree niter)
+static void
+cand_value_at (struct loop *loop, struct iv_cand *cand, tree at, tree niter,
+ aff_tree *val)
{
- tree val;
+ aff_tree step, delta, nit;
+ struct iv *iv = cand->iv;
tree type = TREE_TYPE (iv->base);
- niter = fold_convert (type, niter);
- val = fold_build2 (MULT_EXPR, type, iv->step, niter);
-
- return fold_build2 (PLUS_EXPR, type, iv->base, val);
-}
-
-/* Computes value of candidate CAND at position AT in iteration NITER. */
-
-static tree
-cand_value_at (struct loop *loop, struct iv_cand *cand, tree at, tree niter)
-{
- tree val = iv_value (cand->iv, niter);
- tree type = TREE_TYPE (cand->iv->base);
-
+ tree_to_aff_combination (iv->step, type, &step);
+ tree_to_aff_combination (niter, TREE_TYPE (niter), &nit);
+ aff_combination_convert (&nit, type);
+ aff_combination_mult (&nit, &step, &delta);
if (stmt_after_increment (loop, cand, at))
- val = fold_build2 (PLUS_EXPR, type, val, cand->iv->step);
+ aff_combination_add (&delta, &step);
- return val;
+ tree_to_aff_combination (iv->base, type, val);
+ aff_combination_add (val, &delta);
}
/* Returns period of induction variable iv. */
@@ -3637,6 +3616,7 @@ may_eliminate_iv (struct ivopts_data *data,
tree nit, nit_type;
tree wider_type, period, per_type;
struct loop *loop = data->current_loop;
+ aff_tree bnd;
if (TREE_CODE (cand->iv->step) != INTEGER_CST)
return false;
@@ -3681,7 +3661,8 @@ may_eliminate_iv (struct ivopts_data *data,
fold_convert (wider_type, nit))))
return false;
- *bound = fold_affine_expr (cand_value_at (loop, cand, use->stmt, nit));
+ cand_value_at (loop, cand, use->stmt, nit, &bnd);
+ *bound = aff_combination_to_tree (&bnd);
return true;
}