tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne, [...]): Use integer_zerop/integer_nonzerop instead of...

* tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne,
	assert_no_overflow_lt, assert_loop_rolls_lt,
	number_of_iterations_lt, number_of_iterations_le,
	number_of_iterations_cond, number_of_iterations_exit):
	Use integer_zerop/integer_nonzerop instead of
	null_or_integer_zerop/nonnull_and_integer_nonzerop.
	* tree.h (null_or_integer_zerop, nonnull_and_integer_nonzerop):
	Removed.
	* tree-scalar-evolution.c (simple_iv): Return zero for step of
	an invariant.
	* tree-ssa-loop-ivopts.c (alloc_iv): Do not set step of invariants
	to zero.
	(get_iv): Return NULL for non-scalar types.  Use zero as a step
	of an invariant.
	(determine_biv_step, find_interesting_uses_op,
	find_interesting_uses_cond, find_interesting_uses_stmt,
	add_old_ivs_candidates, determine_use_iv_cost_condition,
	rewrite_use_compare, remove_unused_ivs):
	Use integer_zerop instead of null_or_integer_zerop.
	(struct ifs_ivopts_data): Replace step_p field with step field.
	(idx_find_step): Use zero as a step of an invariant.  Modify
	step instead of *step_p.
	(find_interesting_uses_address): Use zero as a step of an invariant.
	Use integer_zerop instead of null_or_integer_zerop.
	(find_interesting_uses_outside): Call find_interesting_uses_op only
	for phi nodes for real operands.
	(add_candidate_1): Expect step to be non-NULL.
	* tree-ssa-loop-prefetch.c (idx_analyze_ref): Expect step to be
	non-NULL.

From-SVN: r120179
This commit is contained in:
Zdenek Dvorak 2006-12-24 00:05:52 +01:00 committed by Zdenek Dvorak
parent ebf5f54a1d
commit 6e42ce54f7
6 changed files with 93 additions and 97 deletions

View File

@ -1,3 +1,35 @@
2006-12-23 Zdenek Dvorak <dvorakz@suse.cz>
* tree-ssa-loop-niter.c (number_of_iterations_lt_to_ne,
assert_no_overflow_lt, assert_loop_rolls_lt,
number_of_iterations_lt, number_of_iterations_le,
number_of_iterations_cond, number_of_iterations_exit):
Use integer_zerop/integer_nonzerop instead of
null_or_integer_zerop/nonnull_and_integer_nonzerop.
* tree.h (null_or_integer_zerop, nonnull_and_integer_nonzerop):
Removed.
* tree-scalar-evolution.c (simple_iv): Return zero for step of
an invariant.
* tree-ssa-loop-ivopts.c (alloc_iv): Do not set step of invariants
to zero.
(get_iv): Return NULL for non-scalar types. Use zero as a step
of an invariant.
(determine_biv_step, find_interesting_uses_op,
find_interesting_uses_cond, find_interesting_uses_stmt,
add_old_ivs_candidates, determine_use_iv_cost_condition,
rewrite_use_compare, remove_unused_ivs):
Use integer_zerop instead of null_or_integer_zerop.
(struct ifs_ivopts_data): Replace step_p field with step field.
(idx_find_step): Use zero as a step of an invariant. Modify
step instead of *step_p.
(find_interesting_uses_address): Use zero as a step of an invariant.
Use integer_zerop instead of null_or_integer_zerop.
(find_interesting_uses_outside): Call find_interesting_uses_op only
for phi nodes for real operands.
(add_candidate_1): Expect step to be non-NULL.
* tree-ssa-loop-prefetch.c (idx_analyze_ref): Expect step to be
non-NULL.
2006-12-23 Andrew Pinski <pinskia@gmail.com>
* vec.c: Don't include tree.h.

View File

@ -2813,6 +2813,7 @@ simple_iv (struct loop *loop, tree stmt, tree op, affine_iv *iv,
&& !chrec_contains_symbols_defined_in_loop (ev, loop->num))
{
iv->base = ev;
iv->step = build_int_cst (TREE_TYPE (ev), 0);
iv->no_overflow = true;
return true;
}

View File

@ -840,9 +840,7 @@ static struct iv *
alloc_iv (tree base, tree step)
{
struct iv *iv = XCNEW (struct iv);
if (step && integer_zerop (step))
step = NULL_TREE;
gcc_assert (step != NULL_TREE);
iv->base = base;
iv->base_object = determine_base_object (base);
@ -875,14 +873,19 @@ static struct iv *
get_iv (struct ivopts_data *data, tree var)
{
basic_block bb;
tree type = TREE_TYPE (var);
if (!POINTER_TYPE_P (type)
&& !INTEGRAL_TYPE_P (type))
return NULL;
if (!name_info (data, var)->iv)
{
bb = bb_for_stmt (SSA_NAME_DEF_STMT (var));
if (!bb
|| !flow_bb_inside_loop_p (data->current_loop, bb))
set_iv (data, var, var, NULL_TREE);
set_iv (data, var, var, build_int_cst (type, 0));
}
return name_info (data, var)->iv;
@ -904,7 +907,7 @@ determine_biv_step (tree phi)
if (!simple_iv (loop, phi, name, &iv, true))
return NULL_TREE;
return (null_or_integer_zerop (iv.step) ? NULL_TREE : iv.step);
return integer_zerop (iv.step) ? NULL_TREE : iv.step;
}
/* Finds basic ivs. */
@ -1160,7 +1163,7 @@ find_interesting_uses_op (struct ivopts_data *data, tree op)
return use;
}
if (null_or_integer_zerop (iv->step))
if (integer_zerop (iv->step))
{
record_invariant (data, op, true);
return NULL;
@ -1192,7 +1195,7 @@ find_interesting_uses_cond (struct ivopts_data *data, tree stmt, tree *cond_p)
struct iv const_iv;
tree zero = integer_zero_node;
const_iv.step = NULL_TREE;
const_iv.step = integer_zero_node;
if (TREE_CODE (*cond_p) != SSA_NAME
&& !COMPARISON_CLASS_P (*cond_p))
@ -1224,23 +1227,23 @@ find_interesting_uses_cond (struct ivopts_data *data, tree stmt, tree *cond_p)
(!iv0 || !iv1)
/* Eliminating condition based on two ivs would be nontrivial.
??? TODO -- it is not really important to handle this case. */
|| (!null_or_integer_zerop (iv0->step)
&& !null_or_integer_zerop (iv1->step)))
|| (!integer_zerop (iv0->step)
&& !integer_zerop (iv1->step)))
{
find_interesting_uses_op (data, *op0_p);
find_interesting_uses_op (data, *op1_p);
return;
}
if (null_or_integer_zerop (iv0->step)
&& null_or_integer_zerop (iv1->step))
if (integer_zerop (iv0->step)
&& integer_zerop (iv1->step))
{
/* If both are invariants, this is a work for unswitching. */
return;
}
civ = XNEW (struct iv);
*civ = null_or_integer_zerop (iv0->step) ? *iv1: *iv0;
*civ = integer_zerop (iv0->step) ? *iv1: *iv0;
record_use (data, cond_p, civ, stmt, USE_COMPARE);
}
@ -1285,7 +1288,7 @@ struct ifs_ivopts_data
{
struct ivopts_data *ivopts_data;
tree stmt;
tree *step_p;
tree step;
};
static bool
@ -1334,7 +1337,7 @@ idx_find_step (tree base, tree *idx, void *data)
ARRAY_REF path below. */
*idx = iv->base;
if (!iv->step)
if (integer_zerop (iv->step))
return true;
if (TREE_CODE (base) == ARRAY_REF)
@ -1360,11 +1363,7 @@ idx_find_step (tree base, tree *idx, void *data)
}
step = fold_build2 (MULT_EXPR, sizetype, step, iv_step);
if (!*dta->step_p)
*dta->step_p = step;
else
*dta->step_p = fold_build2 (PLUS_EXPR, sizetype, *dta->step_p, step);
dta->step = fold_build2 (PLUS_EXPR, sizetype, dta->step, step);
return true;
}
@ -1456,7 +1455,7 @@ may_be_nonaddressable_p (tree expr)
static void
find_interesting_uses_address (struct ivopts_data *data, tree stmt, tree *op_p)
{
tree base = *op_p, step = NULL;
tree base = *op_p, step = build_int_cst (sizetype, 0);
struct iv *civ;
struct ifs_ivopts_data ifs_ivopts_data;
@ -1509,14 +1508,11 @@ find_interesting_uses_address (struct ivopts_data *data, tree stmt, tree *op_p)
if (TMR_STEP (base))
astep = fold_build2 (MULT_EXPR, type, TMR_STEP (base), astep);
if (step)
step = fold_build2 (PLUS_EXPR, type, step, astep);
else
step = astep;
step = fold_build2 (PLUS_EXPR, type, step, astep);
}
}
if (null_or_integer_zerop (step))
if (integer_zerop (step))
goto fail;
base = tree_mem_ref_addr (type, base);
}
@ -1524,10 +1520,11 @@ find_interesting_uses_address (struct ivopts_data *data, tree stmt, tree *op_p)
{
ifs_ivopts_data.ivopts_data = data;
ifs_ivopts_data.stmt = stmt;
ifs_ivopts_data.step_p = &step;
ifs_ivopts_data.step = build_int_cst (sizetype, 0);
if (!for_each_index (&base, idx_find_step, &ifs_ivopts_data)
|| null_or_integer_zerop (step))
|| integer_zerop (ifs_ivopts_data.step))
goto fail;
step = ifs_ivopts_data.step;
gcc_assert (TREE_CODE (base) != ALIGN_INDIRECT_REF);
gcc_assert (TREE_CODE (base) != MISALIGNED_INDIRECT_REF);
@ -1600,7 +1597,7 @@ find_interesting_uses_stmt (struct ivopts_data *data, tree stmt)
iv = get_iv (data, lhs);
if (iv && !null_or_integer_zerop (iv->step))
if (iv && !integer_zerop (iv->step))
return;
}
@ -1646,7 +1643,7 @@ find_interesting_uses_stmt (struct ivopts_data *data, tree stmt)
lhs = PHI_RESULT (stmt);
iv = get_iv (data, lhs);
if (iv && !null_or_integer_zerop (iv->step))
if (iv && !integer_zerop (iv->step))
return;
}
@ -1676,7 +1673,8 @@ find_interesting_uses_outside (struct ivopts_data *data, edge exit)
for (phi = phi_nodes (exit->dest); phi; phi = PHI_CHAIN (phi))
{
def = PHI_ARG_DEF_FROM_EDGE (phi, exit);
find_interesting_uses_op (data, def);
if (is_gimple_reg (def))
find_interesting_uses_op (data, def);
}
}
@ -1944,8 +1942,7 @@ add_candidate_1 (struct ivopts_data *data,
if (type != orig_type)
{
base = fold_convert (type, base);
if (step)
step = fold_convert (type, step);
step = fold_convert (type, step);
}
}
@ -1970,19 +1967,9 @@ add_candidate_1 (struct ivopts_data *data,
if (!base && !step)
continue;
if (!operand_equal_p (base, cand->iv->base, 0))
continue;
if (null_or_integer_zerop (cand->iv->step))
{
if (null_or_integer_zerop (step))
break;
}
else
{
if (step && operand_equal_p (step, cand->iv->step, 0))
break;
}
if (operand_equal_p (base, cand->iv->base, 0)
&& operand_equal_p (step, cand->iv->step, 0))
break;
}
if (i == n_iv_cands (data))
@ -2136,7 +2123,7 @@ add_old_ivs_candidates (struct ivopts_data *data)
EXECUTE_IF_SET_IN_BITMAP (data->relevant, 0, i, bi)
{
iv = ver_info (data, i)->iv;
if (iv && iv->biv_p && !null_or_integer_zerop (iv->step))
if (iv && iv->biv_p && !integer_zerop (iv->step))
add_old_iv_candidates (data, iv);
}
}
@ -3733,7 +3720,7 @@ determine_use_iv_cost_condition (struct ivopts_data *data,
{
op = TREE_OPERAND (cond, 0);
if (TREE_CODE (op) == SSA_NAME
&& !null_or_integer_zerop (get_iv (data, op)->step))
&& !integer_zerop (get_iv (data, op)->step))
op = TREE_OPERAND (cond, 1);
if (TREE_CODE (op) == SSA_NAME)
{
@ -5151,7 +5138,7 @@ rewrite_use_compare (struct ivopts_data *data,
cond = *use->op_p;
op_p = &TREE_OPERAND (cond, 0);
if (TREE_CODE (*op_p) != SSA_NAME
|| null_or_integer_zerop (get_iv (data, *op_p)->step))
|| integer_zerop (get_iv (data, *op_p)->step))
op_p = &TREE_OPERAND (cond, 1);
op = force_gimple_operand (comp, &stmts, true, SSA_NAME_VAR (*op_p));
@ -5222,7 +5209,7 @@ remove_unused_ivs (struct ivopts_data *data)
info = ver_info (data, j);
if (info->iv
&& !null_or_integer_zerop (info->iv->step)
&& !integer_zerop (info->iv->step)
&& !info->inv_id
&& !info->iv->have_use_for
&& !info->preserve_biv)

View File

@ -193,7 +193,7 @@ number_of_iterations_lt_to_ne (tree type, affine_iv *iv0, affine_iv *iv1,
mod = fold_build2 (MINUS_EXPR, niter_type, step, mod);
tmod = fold_convert (type, mod);
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
{
/* The final value of the iv is iv1->base + MOD, assuming that this
computation does not overflow, and that
@ -256,7 +256,7 @@ assert_no_overflow_lt (tree type, affine_iv *iv0, affine_iv *iv1,
tree bound, d, assumption, diff;
tree niter_type = TREE_TYPE (step);
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
{
/* for (i = iv0->base; i < iv1->base; i += iv0->step) */
if (iv0->no_overflow)
@ -324,7 +324,7 @@ assert_loop_rolls_lt (tree type, affine_iv *iv0, affine_iv *iv1,
tree assumption = boolean_true_node, bound, diff;
tree mbz, mbzl, mbzr;
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
{
diff = fold_build2 (MINUS_EXPR, type,
iv0->step, build_int_cst (type, 1));
@ -384,7 +384,7 @@ number_of_iterations_lt (tree type, affine_iv *iv0, affine_iv *iv1,
tree niter_type = unsigned_type_for (type);
tree delta, step, s;
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
{
niter->control = *iv0;
niter->cmp = LT_EXPR;
@ -402,10 +402,8 @@ number_of_iterations_lt (tree type, affine_iv *iv0, affine_iv *iv1,
fold_convert (niter_type, iv0->base));
/* First handle the special case that the step is +-1. */
if ((iv0->step && integer_onep (iv0->step)
&& null_or_integer_zerop (iv1->step))
|| (iv1->step && integer_all_onesp (iv1->step)
&& null_or_integer_zerop (iv0->step)))
if ((integer_onep (iv0->step) && integer_zerop (iv1->step))
|| (integer_all_onesp (iv1->step) && integer_zerop (iv0->step)))
{
/* for (i = iv0->base; i < iv1->base; i++)
@ -421,7 +419,7 @@ number_of_iterations_lt (tree type, affine_iv *iv0, affine_iv *iv1,
return true;
}
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
step = fold_convert (niter_type, iv0->step);
else
step = fold_convert (niter_type,
@ -479,7 +477,7 @@ number_of_iterations_le (tree type, affine_iv *iv0, affine_iv *iv1,
if (!never_infinite)
{
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
assumption = fold_build2 (NE_EXPR, boolean_type_node,
iv1->base, TYPE_MAX_VALUE (type));
else
@ -493,7 +491,7 @@ number_of_iterations_le (tree type, affine_iv *iv0, affine_iv *iv1,
niter->assumptions, assumption);
}
if (nonnull_and_integer_nonzerop (iv0->step))
if (integer_nonzerop (iv0->step))
iv1->base = fold_build2 (PLUS_EXPR, type,
iv1->base, build_int_cst (type, 1));
else
@ -542,7 +540,7 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
/* Make < comparison from > ones, and for NE_EXPR comparisons, ensure that
the control variable is on lhs. */
if (code == GE_EXPR || code == GT_EXPR
|| (code == NE_EXPR && null_or_integer_zerop (iv0->step)))
|| (code == NE_EXPR && integer_zerop (iv0->step)))
{
SWAP (iv0, iv1);
code = swap_tree_comparison (code);
@ -578,9 +576,9 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
/* If the control induction variable does not overflow, the loop obviously
cannot be infinite. */
if (!null_or_integer_zerop (iv0->step) && iv0->no_overflow)
if (!integer_zerop (iv0->step) && iv0->no_overflow)
never_infinite = true;
else if (!null_or_integer_zerop (iv1->step) && iv1->no_overflow)
else if (!integer_zerop (iv1->step) && iv1->no_overflow)
never_infinite = true;
else
never_infinite = false;
@ -588,7 +586,7 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
/* We can handle the case when neither of the sides of the comparison is
invariant, provided that the test is NE_EXPR. This rarely occurs in
practice, but it is simple enough to manage. */
if (!null_or_integer_zerop (iv0->step) && !null_or_integer_zerop (iv1->step))
if (!integer_zerop (iv0->step) && !integer_zerop (iv1->step))
{
if (code != NE_EXPR)
return false;
@ -596,14 +594,14 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
iv0->step = fold_binary_to_constant (MINUS_EXPR, type,
iv0->step, iv1->step);
iv0->no_overflow = false;
iv1->step = NULL_TREE;
iv1->step = build_int_cst (type, 0);
iv1->no_overflow = true;
}
/* If the result of the comparison is a constant, the loop is weird. More
precise handling would be possible, but the situation is not common enough
to waste time on it. */
if (null_or_integer_zerop (iv0->step) && null_or_integer_zerop (iv1->step))
if (integer_zerop (iv0->step) && integer_zerop (iv1->step))
return false;
/* Ignore loops of while (i-- < 10) type. */
@ -612,7 +610,7 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
if (iv0->step && tree_int_cst_sign_bit (iv0->step))
return false;
if (!null_or_integer_zerop (iv1->step) && !tree_int_cst_sign_bit (iv1->step))
if (!integer_zerop (iv1->step) && !tree_int_cst_sign_bit (iv1->step))
return false;
}
@ -628,7 +626,7 @@ number_of_iterations_cond (tree type, affine_iv *iv0, enum tree_code code,
switch (code)
{
case NE_EXPR:
gcc_assert (null_or_integer_zerop (iv1->step));
gcc_assert (integer_zerop (iv1->step));
return number_of_iterations_ne (type, iv0, iv1->base, niter, never_infinite);
case LT_EXPR:
return number_of_iterations_lt (type, iv0, iv1, niter, never_infinite);
@ -1099,11 +1097,10 @@ number_of_iterations_exit (struct loop *loop, edge exit,
/* We can provide a more specific warning if one of the operator is
constant and the other advances by +1 or -1. */
if (!null_or_integer_zerop (iv1.step)
? (null_or_integer_zerop (iv0.step)
if (!integer_zerop (iv1.step)
? (integer_zerop (iv0.step)
&& (integer_onep (iv1.step) || integer_all_onesp (iv1.step)))
: (iv0.step
&& (integer_onep (iv0.step) || integer_all_onesp (iv0.step))))
: (integer_onep (iv0.step) || integer_all_onesp (iv0.step)))
wording =
flag_unsafe_loop_optimizations
? N_("assuming that the loop is not infinite")

View File

@ -337,14 +337,9 @@ idx_analyze_ref (tree base, tree *index, void *data)
ibase = iv.base;
step = iv.step;
if (null_or_integer_zerop (step))
istep = 0;
else
{
if (!cst_and_fits_in_hwi (step))
return false;
istep = int_cst_value (step);
}
if (!cst_and_fits_in_hwi (step))
return false;
istep = int_cst_value (step);
if (TREE_CODE (ibase) == PLUS_EXPR
&& cst_and_fits_in_hwi (TREE_OPERAND (ibase, 1)))

View File

@ -4075,22 +4075,6 @@ extern int integer_pow2p (tree);
extern int integer_nonzerop (tree);
/* Returns true if X is either NULL or zero. */
static inline bool
null_or_integer_zerop (tree x)
{
return x == NULL_TREE || integer_zerop (x);
}
/* Returns true if X is non-NULL and non-zero. */
static inline bool
nonnull_and_integer_nonzerop (tree x)
{
return x != NULL_TREE && integer_nonzerop (x);
}
extern bool cst_and_fits_in_hwi (tree);
extern tree num_ending_zeros (tree);