edge
single_dom_exit (struct loop *loop)
{
- edge exit = loop->single_exit;
+ edge exit = single_exit (loop);
if (!exit)
return NULL;
enum tree_code code = TREE_CODE (expr);
tree base, obj, op0, op1;
+ /* If this is a pointer casted to any type, we need to determine
+ the base object for the pointer; so handle conversions before
+ throwing away non-pointer expressions. */
+ if (TREE_CODE (expr) == NOP_EXPR
+ || TREE_CODE (expr) == CONVERT_EXPR)
+ return determine_base_object (TREE_OPERAND (expr, 0));
+
if (!POINTER_TYPE_P (TREE_TYPE (expr)))
return NULL_TREE;
return fold_build2 (code, ptr_type_node, op0, op1);
- case NOP_EXPR:
- case CONVERT_EXPR:
- return determine_base_object (TREE_OPERAND (expr, 0));
-
default:
return fold_convert (ptr_type_node, expr);
}
iv->base = NULL_TREE;
iv->step = NULL_TREE;
- if (TREE_CODE (stmt) != MODIFY_EXPR)
+ if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
return false;
- lhs = TREE_OPERAND (stmt, 0);
+ lhs = GIMPLE_STMT_OPERAND (stmt, 0);
if (TREE_CODE (lhs) != SSA_NAME)
return false;
- if (!simple_iv (loop, stmt, TREE_OPERAND (stmt, 1), iv, true))
+ if (!simple_iv (loop, stmt, GIMPLE_STMT_OPERAND (stmt, 1), iv, true))
return false;
iv->base = expand_simple_operations (iv->base);
if (!find_givs_in_stmt_scev (data, stmt, &iv))
return;
- set_iv (data, TREE_OPERAND (stmt, 0), iv.base, iv.step);
+ set_iv (data, GIMPLE_STMT_OPERAND (stmt, 0), iv.base, iv.step);
}
/* Finds general ivs in basic block BB. */
stmt = SSA_NAME_DEF_STMT (op);
gcc_assert (TREE_CODE (stmt) == PHI_NODE
- || TREE_CODE (stmt) == MODIFY_EXPR);
+ || TREE_CODE (stmt) == GIMPLE_MODIFY_STMT);
use = record_use (data, NULL, civ, stmt, USE_NONLINEAR_EXPR);
iv->use_id = use->id;
return true;
}
- if (!EXPR_P (expr))
+ if (!EXPR_P (expr) && !GIMPLE_STMT_P (expr))
return false;
len = TREE_CODE_LENGTH (TREE_CODE (expr));
return;
}
- if (TREE_CODE (stmt) == MODIFY_EXPR)
+ if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT)
{
- lhs = TREE_OPERAND (stmt, 0);
- rhs = TREE_OPERAND (stmt, 1);
+ lhs = GIMPLE_STMT_OPERAND (stmt, 0);
+ rhs = GIMPLE_STMT_OPERAND (stmt, 1);
if (TREE_CODE (lhs) == SSA_NAME)
{
switch (TREE_CODE_CLASS (TREE_CODE (rhs)))
{
case tcc_comparison:
- find_interesting_uses_cond (data, stmt, &TREE_OPERAND (stmt, 1));
+ find_interesting_uses_cond (data, stmt,
+ &GIMPLE_STMT_OPERAND (stmt, 1));
return;
case tcc_reference:
- find_interesting_uses_address (data, stmt, &TREE_OPERAND (stmt, 1));
+ find_interesting_uses_address (data, stmt,
+ &GIMPLE_STMT_OPERAND (stmt, 1));
if (REFERENCE_CLASS_P (lhs))
- find_interesting_uses_address (data, stmt, &TREE_OPERAND (stmt, 0));
+ find_interesting_uses_address (data, stmt,
+ &GIMPLE_STMT_OPERAND (stmt, 0));
return;
default: ;
if (REFERENCE_CLASS_P (lhs)
&& is_gimple_val (rhs))
{
- find_interesting_uses_address (data, stmt, &TREE_OPERAND (stmt, 0));
+ find_interesting_uses_address (data, stmt,
+ &GIMPLE_STMT_OPERAND (stmt, 0));
find_interesting_uses_op (data, rhs);
return;
}
}
/* Returns variant of TYPE that can be used as base for different uses.
- For integer types, we return unsigned variant of the type, which
- avoids problems with overflows. For pointer types, we return void *. */
+ We return unsigned type with the same precision, which avoids problems
+ with overflows. */
static tree
generic_type_for (tree type)
{
if (POINTER_TYPE_P (type))
- return ptr_type_node;
+ return unsigned_type_for (type);
if (TYPE_UNSIGNED (type))
return type;
return (w >> bitno) & 1;
}
-/* If we can prove that TOP = cst * BOT for some constant cst in TYPE,
- return cst. Otherwise return NULL_TREE. */
+/* If we can prove that TOP = cst * BOT for some constant cst,
+ store cst to MUL and return true. Otherwise return false.
+ The returned value is always sign-extended, regardless of the
+ signedness of TOP and BOT. */
-static tree
-constant_multiple_of (tree type, tree top, tree bot)
+static bool
+constant_multiple_of (tree top, tree bot, double_int *mul)
{
- tree res, mby, p0, p1;
+ tree mby;
enum tree_code code;
- bool negate;
+ double_int res, p0, p1;
+ unsigned precision = TYPE_PRECISION (TREE_TYPE (top));
STRIP_NOPS (top);
STRIP_NOPS (bot);
if (operand_equal_p (top, bot, 0))
- return build_int_cst (type, 1);
+ {
+ *mul = double_int_one;
+ return true;
+ }
code = TREE_CODE (top);
switch (code)
case MULT_EXPR:
mby = TREE_OPERAND (top, 1);
if (TREE_CODE (mby) != INTEGER_CST)
- return NULL_TREE;
+ return false;
- res = constant_multiple_of (type, TREE_OPERAND (top, 0), bot);
- if (!res)
- return NULL_TREE;
+ if (!constant_multiple_of (TREE_OPERAND (top, 0), bot, &res))
+ return false;
- return fold_binary_to_constant (MULT_EXPR, type, res,
- fold_convert (type, mby));
+ *mul = double_int_sext (double_int_mul (res, tree_to_double_int (mby)),
+ precision);
+ return true;
case PLUS_EXPR:
case MINUS_EXPR:
- p0 = constant_multiple_of (type, TREE_OPERAND (top, 0), bot);
- if (!p0)
- return NULL_TREE;
- p1 = constant_multiple_of (type, TREE_OPERAND (top, 1), bot);
- if (!p1)
- return NULL_TREE;
+ if (!constant_multiple_of (TREE_OPERAND (top, 0), bot, &p0)
+ || !constant_multiple_of (TREE_OPERAND (top, 1), bot, &p1))
+ return false;
- return fold_binary_to_constant (code, type, p0, p1);
+ if (code == MINUS_EXPR)
+ p1 = double_int_neg (p1);
+ *mul = double_int_sext (double_int_add (p0, p1), precision);
+ return true;
case INTEGER_CST:
if (TREE_CODE (bot) != INTEGER_CST)
- return NULL_TREE;
-
- bot = fold_convert (type, bot);
- top = fold_convert (type, top);
-
- /* If BOT seems to be negative, try dividing by -BOT instead, and negate
- the result afterwards. */
- if (tree_int_cst_sign_bit (bot))
- {
- negate = true;
- bot = fold_unary_to_constant (NEGATE_EXPR, type, bot);
- }
- else
- negate = false;
-
- /* Ditto for TOP. */
- if (tree_int_cst_sign_bit (top))
- {
- negate = !negate;
- top = fold_unary_to_constant (NEGATE_EXPR, type, top);
- }
-
- if (!zero_p (fold_binary_to_constant (TRUNC_MOD_EXPR, type, top, bot)))
- return NULL_TREE;
+ return false;
- res = fold_binary_to_constant (EXACT_DIV_EXPR, type, top, bot);
- if (negate)
- res = fold_unary_to_constant (NEGATE_EXPR, type, res);
- return res;
+ p0 = double_int_sext (tree_to_double_int (bot), precision);
+ p1 = double_int_sext (tree_to_double_int (top), precision);
+ if (double_int_zero_p (p1))
+ return false;
+ *mul = double_int_sext (double_int_sdivmod (p0, p1, FLOOR_DIV_EXPR, &res),
+ precision);
+ return double_int_zero_p (res);
default:
- return NULL_TREE;
+ return false;
}
}
aff_combination_add_elt (comb1, comb2->rest, 1);
}
+/* Convert COMB to TYPE. */
+
+static void
+aff_combination_convert (tree type, struct affine_tree_combination *comb)
+{
+ unsigned prec = TYPE_PRECISION (type);
+ unsigned i;
+
+ /* If the precision of both types is the same, it suffices to change the type
+ of the whole combination -- the elements are allowed to have another type
+ equivalent wrto STRIP_NOPS. */
+ if (prec == TYPE_PRECISION (comb->type))
+ {
+ comb->type = type;
+ return;
+ }
+
+ comb->mask = (((unsigned HOST_WIDE_INT) 2 << (prec - 1)) - 1);
+ comb->offset = comb->offset & comb->mask;
+
+ /* The type of the elements can be different from comb->type only as
+ much as what STRIP_NOPS would remove. We can just directly cast
+ to TYPE. */
+ for (i = 0; i < comb->n; i++)
+ comb->elts[i] = fold_convert (type, comb->elts[i]);
+ if (comb->rest)
+ comb->rest = fold_convert (type, comb->rest);
+
+ comb->type = type;
+}
+
/* Splits EXPR into an affine combination of parts. */
static void
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
+ type of A and B. */
+
+static tree
+determine_common_wider_type (tree *a, tree *b)
+{
+ tree wider_type = NULL;
+ tree suba, subb;
+ tree atype = TREE_TYPE (*a);
+
+ if ((TREE_CODE (*a) == NOP_EXPR
+ || TREE_CODE (*a) == CONVERT_EXPR))
+ {
+ suba = TREE_OPERAND (*a, 0);
+ wider_type = TREE_TYPE (suba);
+ if (TYPE_PRECISION (wider_type) < TYPE_PRECISION (atype))
+ return atype;
+ }
+ else
+ return atype;
+
+ if ((TREE_CODE (*b) == NOP_EXPR
+ || TREE_CODE (*b) == CONVERT_EXPR))
+ {
+ subb = TREE_OPERAND (*b, 0);
+ if (TYPE_PRECISION (wider_type) != TYPE_PRECISION (TREE_TYPE (subb)))
+ return atype;
+ }
+ else
+ return atype;
+
+ *a = suba;
+ *b = subb;
+ return wider_type;
+}
+
/* Determines the expression by that USE is expressed from induction variable
CAND at statement AT in LOOP. The expression is stored in a decomposed
form into AFF. Returns false if USE cannot be expressed using CAND. */
tree cbase = cand->iv->base;
tree cstep = cand->iv->step;
tree utype = TREE_TYPE (ubase), ctype = TREE_TYPE (cbase);
+ tree common_type;
tree uutype;
tree expr, delta;
tree ratio;
HOST_WIDE_INT ratioi;
struct affine_tree_combination cbase_aff, expr_aff;
tree cstep_orig = cstep, ustep_orig = ustep;
+ double_int rat;
if (TYPE_PRECISION (utype) > TYPE_PRECISION (ctype))
{
}
else
{
- ratio = constant_multiple_of (uutype, ustep_orig, cstep_orig);
- if (!ratio)
+ if (!constant_multiple_of (ustep_orig, cstep_orig, &rat))
return false;
+ ratio = double_int_to_tree (uutype, rat);
/* Ratioi is only used to detect special cases when the multiplicative
- factor is 1 or -1, so if we cannot convert ratio to HOST_WIDE_INT,
- we may set it to 0. We prefer cst_and_fits_in_hwi/int_cst_value
- to integer_onep/integer_all_onesp, since the former ignores
- TREE_OVERFLOW. */
- if (cst_and_fits_in_hwi (ratio))
- ratioi = int_cst_value (ratio);
- else if (integer_onep (ratio))
- ratioi = 1;
- else if (integer_all_onesp (ratio))
- ratioi = -1;
+ factor is 1 or -1, so if rat does not fit to HOST_WIDE_INT, we may
+ set it to 0. */
+ if (double_int_fits_in_shwi_p (rat))
+ ratioi = double_int_to_shwi (rat);
else
ratioi = 0;
}
+ /* In case both UBASE and CBASE are shortened to UUTYPE from some common
+ type, we achieve better folding by computing their difference in this
+ wider type, and cast the result to UUTYPE. We do not need to worry about
+ overflows, as all the arithmetics will in the end be performed in UUTYPE
+ anyway. */
+ common_type = determine_common_wider_type (&ubase, &cbase);
+
/* We may need to shift the value if we are after the increment. */
if (stmt_after_increment (loop, cand, at))
- cbase = fold_build2 (PLUS_EXPR, uutype, cbase, cstep);
+ {
+ if (uutype != common_type)
+ cstep = fold_convert (common_type, cstep);
+ cbase = fold_build2 (PLUS_EXPR, common_type, cbase, cstep);
+ }
/* use = ubase - ratio * cbase + ratio * var.
happen, fold is able to apply the distributive law to obtain this form
anyway. */
- if (TYPE_PRECISION (uutype) > HOST_BITS_PER_WIDE_INT)
+ if (TYPE_PRECISION (common_type) > HOST_BITS_PER_WIDE_INT)
{
/* Let's compute in trees and just return the result in AFF. This case
should not be very common, and fold itself is not that bad either,
is not that urgent. */
if (ratioi == 1)
{
- delta = fold_build2 (MINUS_EXPR, uutype, ubase, cbase);
+ delta = fold_build2 (MINUS_EXPR, common_type, ubase, cbase);
+ if (uutype != common_type)
+ delta = fold_convert (uutype, delta);
expr = fold_build2 (PLUS_EXPR, uutype, expr, delta);
}
else if (ratioi == -1)
{
- delta = fold_build2 (PLUS_EXPR, uutype, ubase, cbase);
+ delta = fold_build2 (PLUS_EXPR, common_type, ubase, cbase);
+ if (uutype != common_type)
+ delta = fold_convert (uutype, delta);
expr = fold_build2 (MINUS_EXPR, uutype, delta, expr);
}
else
{
- delta = fold_build2 (MULT_EXPR, uutype, cbase, ratio);
- delta = fold_build2 (MINUS_EXPR, uutype, ubase, delta);
+ delta = fold_build2 (MULT_EXPR, common_type, cbase, ratio);
+ delta = fold_build2 (MINUS_EXPR, common_type, ubase, delta);
+ if (uutype != common_type)
+ delta = fold_convert (uutype, delta);
expr = fold_build2 (MULT_EXPR, uutype, ratio, expr);
expr = fold_build2 (PLUS_EXPR, uutype, delta, expr);
}
possible to compute ratioi. */
gcc_assert (ratioi);
- tree_to_aff_combination (ubase, uutype, aff);
- tree_to_aff_combination (cbase, uutype, &cbase_aff);
+ tree_to_aff_combination (ubase, common_type, aff);
+ tree_to_aff_combination (cbase, common_type, &cbase_aff);
tree_to_aff_combination (expr, uutype, &expr_aff);
aff_combination_scale (&cbase_aff, -ratioi);
aff_combination_scale (&expr_aff, ratioi);
aff_combination_add (aff, &cbase_aff);
+ if (common_type != uutype)
+ aff_combination_convert (uutype, aff);
aff_combination_add (aff, &expr_aff);
return true;
return cost;
}
-/* Returns true if multiplying by RATIO is allowed in address. */
+/* Returns true if multiplying by RATIO is allowed in an address. Test the
+ validity for a memory reference accessing memory of mode MODE. */
bool
-multiplier_allowed_in_address_p (HOST_WIDE_INT ratio)
+multiplier_allowed_in_address_p (HOST_WIDE_INT ratio, enum machine_mode mode)
{
#define MAX_RATIO 128
- static sbitmap valid_mult;
+ static sbitmap valid_mult[MAX_MACHINE_MODE];
- if (!valid_mult)
+ if (!valid_mult[mode])
{
rtx reg1 = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1);
rtx addr;
HOST_WIDE_INT i;
- valid_mult = sbitmap_alloc (2 * MAX_RATIO + 1);
- sbitmap_zero (valid_mult);
+ valid_mult[mode] = sbitmap_alloc (2 * MAX_RATIO + 1);
+ sbitmap_zero (valid_mult[mode]);
addr = gen_rtx_fmt_ee (MULT, Pmode, reg1, NULL_RTX);
for (i = -MAX_RATIO; i <= MAX_RATIO; i++)
{
XEXP (addr, 1) = gen_int_mode (i, Pmode);
- if (memory_address_p (Pmode, addr))
- SET_BIT (valid_mult, i + MAX_RATIO);
+ if (memory_address_p (mode, addr))
+ SET_BIT (valid_mult[mode], i + MAX_RATIO);
}
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, " allowed multipliers:");
for (i = -MAX_RATIO; i <= MAX_RATIO; i++)
- if (TEST_BIT (valid_mult, i + MAX_RATIO))
+ if (TEST_BIT (valid_mult[mode], i + MAX_RATIO))
fprintf (dump_file, " %d", (int) i);
fprintf (dump_file, "\n");
fprintf (dump_file, "\n");
if (ratio > MAX_RATIO || ratio < -MAX_RATIO)
return false;
- return TEST_BIT (valid_mult, ratio + MAX_RATIO);
+ return TEST_BIT (valid_mult[mode], ratio + MAX_RATIO);
}
/* Returns cost of address in shape symbol + var + OFFSET + RATIO * index.
If SYMBOL_PRESENT is false, symbol is omitted. If VAR_PRESENT is false,
- variable is omitted. The created memory accesses MODE.
-
+ variable is omitted. Compute the cost for a memory reference that accesses
+ a memory location of mode MEM_MODE.
+
TODO -- there must be some better way. This all is quite crude. */
static unsigned
get_address_cost (bool symbol_present, bool var_present,
- unsigned HOST_WIDE_INT offset, HOST_WIDE_INT ratio)
+ unsigned HOST_WIDE_INT offset, HOST_WIDE_INT ratio,
+ enum machine_mode mem_mode)
{
- static bool initialized = false;
- static HOST_WIDE_INT rat, off;
- static HOST_WIDE_INT min_offset, max_offset;
- static unsigned costs[2][2][2][2];
+ static bool initialized[MAX_MACHINE_MODE];
+ static HOST_WIDE_INT rat[MAX_MACHINE_MODE], off[MAX_MACHINE_MODE];
+ static HOST_WIDE_INT min_offset[MAX_MACHINE_MODE], max_offset[MAX_MACHINE_MODE];
+ static unsigned costs[MAX_MACHINE_MODE][2][2][2][2];
unsigned cost, acost;
- rtx seq, addr, base;
bool offset_p, ratio_p;
- rtx reg1;
HOST_WIDE_INT s_offset;
unsigned HOST_WIDE_INT mask;
unsigned bits;
- if (!initialized)
+ if (!initialized[mem_mode])
{
HOST_WIDE_INT i;
- initialized = true;
+ HOST_WIDE_INT start = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
+ int old_cse_not_expected;
+ unsigned sym_p, var_p, off_p, rat_p, add_c;
+ rtx seq, addr, base;
+ rtx reg0, reg1;
+
+ initialized[mem_mode] = true;
reg1 = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1);
addr = gen_rtx_fmt_ee (PLUS, Pmode, reg1, NULL_RTX);
- for (i = 1; i <= 1 << 20; i <<= 1)
+ for (i = start; i <= 1 << 20; i <<= 1)
{
XEXP (addr, 1) = gen_int_mode (i, Pmode);
- if (!memory_address_p (Pmode, addr))
+ if (!memory_address_p (mem_mode, addr))
break;
}
- max_offset = i >> 1;
- off = max_offset;
+ max_offset[mem_mode] = i == start ? 0 : i >> 1;
+ off[mem_mode] = max_offset[mem_mode];
- for (i = 1; i <= 1 << 20; i <<= 1)
+ for (i = start; i <= 1 << 20; i <<= 1)
{
XEXP (addr, 1) = gen_int_mode (-i, Pmode);
- if (!memory_address_p (Pmode, addr))
+ if (!memory_address_p (mem_mode, addr))
break;
}
- min_offset = -(i >> 1);
+ min_offset[mem_mode] = i == start ? 0 : -(i >> 1);
if (dump_file && (dump_flags & TDF_DETAILS))
{
fprintf (dump_file, "get_address_cost:\n");
- fprintf (dump_file, " min offset %d\n", (int) min_offset);
- fprintf (dump_file, " max offset %d\n", (int) max_offset);
+ fprintf (dump_file, " min offset %s %d\n",
+ GET_MODE_NAME (mem_mode),
+ (int) min_offset[mem_mode]);
+ fprintf (dump_file, " max offset %s %d\n",
+ GET_MODE_NAME (mem_mode),
+ (int) max_offset[mem_mode]);
}
- rat = 1;
+ rat[mem_mode] = 1;
for (i = 2; i <= MAX_RATIO; i++)
- if (multiplier_allowed_in_address_p (i))
+ if (multiplier_allowed_in_address_p (i, mem_mode))
{
- rat = i;
+ rat[mem_mode] = i;
break;
}
+
+ /* Compute the cost of various addressing modes. */
+ acost = 0;
+ reg0 = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1);
+ reg1 = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 2);
+
+ for (i = 0; i < 16; i++)
+ {
+ sym_p = i & 1;
+ var_p = (i >> 1) & 1;
+ off_p = (i >> 2) & 1;
+ rat_p = (i >> 3) & 1;
+
+ addr = reg0;
+ if (rat_p)
+ addr = gen_rtx_fmt_ee (MULT, Pmode, addr,
+ gen_int_mode (rat[mem_mode], Pmode));
+
+ if (var_p)
+ addr = gen_rtx_fmt_ee (PLUS, Pmode, addr, reg1);
+
+ if (sym_p)
+ {
+ base = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (""));
+ if (off_p)
+ base = gen_rtx_fmt_e (CONST, Pmode,
+ gen_rtx_fmt_ee (PLUS, Pmode,
+ base,
+ gen_int_mode (off[mem_mode],
+ Pmode)));
+ }
+ else if (off_p)
+ base = gen_int_mode (off[mem_mode], Pmode);
+ else
+ base = NULL_RTX;
+
+ if (base)
+ addr = gen_rtx_fmt_ee (PLUS, Pmode, addr, base);
+
+ start_sequence ();
+ /* To avoid splitting addressing modes, pretend that no cse will
+ follow. */
+ old_cse_not_expected = cse_not_expected;
+ cse_not_expected = true;
+ addr = memory_address (mem_mode, addr);
+ cse_not_expected = old_cse_not_expected;
+ seq = get_insns ();
+ end_sequence ();
+
+ acost = seq_cost (seq);
+ acost += address_cost (addr, mem_mode);
+
+ if (!acost)
+ acost = 1;
+ costs[mem_mode][sym_p][var_p][off_p][rat_p] = acost;
+ }
+
+ /* On some targets, it is quite expensive to load symbol to a register,
+ which makes addresses that contain symbols look much more expensive.
+ However, the symbol will have to be loaded in any case before the
+ loop (and quite likely we have it in register already), so it does not
+ make much sense to penalize them too heavily. So make some final
+ tweaks for the SYMBOL_PRESENT modes:
+
+ If VAR_PRESENT is false, and the mode obtained by changing symbol to
+ var is cheaper, use this mode with small penalty.
+ If VAR_PRESENT is true, try whether the mode with
+ SYMBOL_PRESENT = false is cheaper even with cost of addition, and
+ if this is the case, use it. */
+ add_c = add_cost (Pmode);
+ for (i = 0; i < 8; i++)
+ {
+ var_p = i & 1;
+ off_p = (i >> 1) & 1;
+ rat_p = (i >> 2) & 1;
+
+ acost = costs[mem_mode][0][1][off_p][rat_p] + 1;
+ if (var_p)
+ acost += add_c;
+
+ if (acost < costs[mem_mode][1][var_p][off_p][rat_p])
+ costs[mem_mode][1][var_p][off_p][rat_p] = acost;
+ }
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Address costs:\n");
+
+ for (i = 0; i < 16; i++)
+ {
+ sym_p = i & 1;
+ var_p = (i >> 1) & 1;
+ off_p = (i >> 2) & 1;
+ rat_p = (i >> 3) & 1;
+
+ fprintf (dump_file, " ");
+ if (sym_p)
+ fprintf (dump_file, "sym + ");
+ if (var_p)
+ fprintf (dump_file, "var + ");
+ if (off_p)
+ fprintf (dump_file, "cst + ");
+ if (rat_p)
+ fprintf (dump_file, "rat * ");
+
+ acost = costs[mem_mode][sym_p][var_p][off_p][rat_p];
+ fprintf (dump_file, "index costs %d\n", acost);
+ }
+ fprintf (dump_file, "\n");
+ }
}
bits = GET_MODE_BITSIZE (Pmode);
cost = 0;
offset_p = (s_offset != 0
- && min_offset <= s_offset && s_offset <= max_offset);
+ && min_offset[mem_mode] <= s_offset
+ && s_offset <= max_offset[mem_mode]);
ratio_p = (ratio != 1
- && multiplier_allowed_in_address_p (ratio));
+ && multiplier_allowed_in_address_p (ratio, mem_mode));
if (ratio != 1 && !ratio_p)
cost += multiply_by_cost (ratio, Pmode);
if (s_offset && !offset_p && !symbol_present)
- {
- cost += add_cost (Pmode);
- var_present = true;
- }
-
- acost = costs[symbol_present][var_present][offset_p][ratio_p];
- if (!acost)
- {
- int old_cse_not_expected;
- acost = 0;
-
- addr = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1);
- reg1 = gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 2);
- if (ratio_p)
- addr = gen_rtx_fmt_ee (MULT, Pmode, addr, gen_int_mode (rat, Pmode));
-
- if (var_present)
- addr = gen_rtx_fmt_ee (PLUS, Pmode, addr, reg1);
-
- if (symbol_present)
- {
- base = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (""));
- if (offset_p)
- base = gen_rtx_fmt_e (CONST, Pmode,
- gen_rtx_fmt_ee (PLUS, Pmode,
- base,
- gen_int_mode (off, Pmode)));
- }
- else if (offset_p)
- base = gen_int_mode (off, Pmode);
- else
- base = NULL_RTX;
-
- if (base)
- addr = gen_rtx_fmt_ee (PLUS, Pmode, addr, base);
-
- start_sequence ();
- /* To avoid splitting addressing modes, pretend that no cse will
- follow. */
- old_cse_not_expected = cse_not_expected;
- cse_not_expected = true;
- addr = memory_address (Pmode, addr);
- cse_not_expected = old_cse_not_expected;
- seq = get_insns ();
- end_sequence ();
-
- acost = seq_cost (seq);
- acost += address_cost (addr, Pmode);
-
- if (!acost)
- acost = 1;
- costs[symbol_present][var_present][offset_p][ratio_p] = acost;
- }
+ cost += add_cost (Pmode);
+ acost = costs[mem_mode][symbol_present][var_present][offset_p][ratio_p];
return cost + acost;
}
}
else
{
- tree rat;
+ double_int rat;
- rat = constant_multiple_of (utype, ustep, cstep);
-
- if (!rat)
+ if (!constant_multiple_of (ustep, cstep, &rat))
return INFTY;
-
- if (cst_and_fits_in_hwi (rat))
- ratio = int_cst_value (rat);
- else if (integer_onep (rat))
- ratio = 1;
- else if (integer_all_onesp (rat))
- ratio = -1;
+
+ if (double_int_fits_in_shwi_p (rat))
+ ratio = double_int_to_shwi (rat);
else
return INFTY;
}
(symbol/var/const parts may be omitted). If we are looking for an address,
find the cost of addressing this. */
if (address_p)
- return cost + get_address_cost (symbol_present, var_present, offset, ratio);
+ return cost + get_address_cost (symbol_present, var_present, offset, ratio,
+ TYPE_MODE (TREE_TYPE (*use->op_p)));
/* Otherwise estimate the costs for computing the expression. */
aratio = ratio > 0 ? ratio : -ratio;
fprintf (dump_file, " %d\t%d\n", i, cand->cost);
}
-if (dump_file && (dump_flags & TDF_DETAILS))
- fprintf (dump_file, "\n");
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "\n");
}
/* Calculates cost for having SIZE induction variables. */
tree step, ctype, utype;
enum tree_code incr_code = PLUS_EXPR;
- gcc_assert (TREE_CODE (use->stmt) == MODIFY_EXPR);
- gcc_assert (TREE_OPERAND (use->stmt, 0) == cand->var_after);
+ gcc_assert (TREE_CODE (use->stmt) == GIMPLE_MODIFY_STMT);
+ gcc_assert (GIMPLE_STMT_OPERAND (use->stmt, 0) == cand->var_after);
step = cand->iv->step;
ctype = TREE_TYPE (step);
computations in the loop -- otherwise, the computation
we rely upon may be removed in remove_unused_ivs,
thus leading to ICE. */
- op = TREE_OPERAND (use->stmt, 1);
+ op = GIMPLE_STMT_OPERAND (use->stmt, 1);
if (TREE_CODE (op) == PLUS_EXPR
|| TREE_CODE (op) == MINUS_EXPR)
{
}
break;
- case MODIFY_EXPR:
- tgt = TREE_OPERAND (use->stmt, 0);
+ case GIMPLE_MODIFY_STMT:
+ tgt = GIMPLE_STMT_OPERAND (use->stmt, 0);
bsi = bsi_for_stmt (use->stmt);
break;
{
if (stmts)
bsi_insert_after (&bsi, stmts, BSI_CONTINUE_LINKING);
- ass = build2 (MODIFY_EXPR, TREE_TYPE (tgt), tgt, op);
+ ass = build2_gimple (GIMPLE_MODIFY_STMT, tgt, op);
bsi_insert_after (&bsi, ass, BSI_NEW_STMT);
remove_statement (use->stmt, false);
SSA_NAME_DEF_STMT (tgt) = ass;
{
if (stmts)
bsi_insert_before (&bsi, stmts, BSI_SAME_STMT);
- TREE_OPERAND (use->stmt, 1) = op;
+ GIMPLE_STMT_OPERAND (use->stmt, 1) = op;
}
}
return changed;
}
-/* Main entry point. Optimizes induction variables in LOOPS. */
+/* Main entry point. Optimizes induction variables in loops. */
void
-tree_ssa_iv_optimize (struct loops *loops)
+tree_ssa_iv_optimize (void)
{
struct loop *loop;
struct ivopts_data data;
tree_ssa_iv_optimize_init (&data);
/* Optimize the loops starting with the innermost ones. */
- loop = loops->tree_root;
+ loop = current_loops->tree_root;
while (loop->inner)
loop = loop->inner;
/* Scan the loops, inner ones first. */
- while (loop != loops->tree_root)
+ while (loop != current_loops->tree_root)
{
if (dump_file && (dump_flags & TDF_DETAILS))
flow_loop_dump (loop, dump_file, NULL, 1);