diff options
Diffstat (limited to 'gcc/tree-ssa-loop-ivopts.c')
-rw-r--r-- | gcc/tree-ssa-loop-ivopts.c | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 798f57f6c28..b16b9b52dc4 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -1563,19 +1563,19 @@ idx_record_use (tree base, tree *idx, signedness of TOP and BOT. */ static bool -constant_multiple_of (tree top, tree bot, double_int *mul) +constant_multiple_of (tree top, tree bot, max_wide_int *mul) { tree mby; enum tree_code code; - double_int res, p0, p1; unsigned precision = TYPE_PRECISION (TREE_TYPE (top)); + max_wide_int res, p0, p1; STRIP_NOPS (top); STRIP_NOPS (bot); if (operand_equal_p (top, bot, 0)) { - *mul = double_int_one; + *mul = 1; return true; } @@ -1590,7 +1590,7 @@ constant_multiple_of (tree top, tree bot, double_int *mul) if (!constant_multiple_of (TREE_OPERAND (top, 0), bot, &res)) return false; - *mul = (res * tree_to_double_int (mby)).sext (precision); + *mul = wi::sext (res * mby, precision); return true; case PLUS_EXPR: @@ -1601,19 +1601,19 @@ constant_multiple_of (tree top, tree bot, double_int *mul) if (code == MINUS_EXPR) p1 = -p1; - *mul = (p0 + p1).sext (precision); + *mul = wi::sext (p0 + p1, precision); return true; case INTEGER_CST: if (TREE_CODE (bot) != INTEGER_CST) return false; - p0 = tree_to_double_int (top).sext (precision); - p1 = tree_to_double_int (bot).sext (precision); - if (p1.is_zero ()) + p0 = wi::sext (top, precision); + p1 = wi::sext (bot, precision); + if (p1 == 0) return false; - *mul = p0.sdivmod (p1, FLOOR_DIV_EXPR, &res).sext (precision); - return res.is_zero (); + *mul = wi::sext (wi::divmod_trunc (p0, p1, SIGNED, &res), precision); + return res == 0; default: return false; @@ -2028,7 +2028,7 @@ strip_offset_1 (tree expr, bool inside_addr, bool top_compref, switch (code) { case INTEGER_CST: - if (!cst_and_fits_in_hwi (expr) + if (!cst_fits_shwi_p (expr) || integer_zerop (expr)) return orig_expr; @@ -2065,7 +2065,7 @@ strip_offset_1 (tree expr, bool inside_addr, bool top_compref, case MULT_EXPR: op1 = TREE_OPERAND (expr, 1); - if (!cst_and_fits_in_hwi (op1)) + if (!cst_fits_shwi_p (op1)) return orig_expr; op0 = TREE_OPERAND (expr, 0); @@ -2087,7 +2087,7 @@ strip_offset_1 (tree expr, bool inside_addr, bool top_compref, return orig_expr; step = array_ref_element_size (expr); - if (!cst_and_fits_in_hwi (step)) + if (!cst_fits_shwi_p (step)) break; st = int_cst_value (step); @@ -2112,7 +2112,7 @@ strip_offset_1 (tree expr, bool inside_addr, bool top_compref, tmp = component_ref_field_offset (expr); if (top_compref - && cst_and_fits_in_hwi (tmp)) + && cst_fits_shwi_p (tmp)) { /* Strip the component reference completely. */ op0 = TREE_OPERAND (expr, 0); @@ -2364,7 +2364,7 @@ add_autoinc_candidates (struct ivopts_data *data, tree base, tree step, if (use_bb->loop_father != data->current_loop || !dominated_by_p (CDI_DOMINATORS, data->current_loop->latch, use_bb) || stmt_could_throw_p (use->stmt) - || !cst_and_fits_in_hwi (step)) + || !cst_fits_shwi_p (step)) return; cstepi = int_cst_value (step); @@ -2627,6 +2627,9 @@ new_cost (unsigned runtime, unsigned complexity) { comp_cost cost; + static int ct = 0; + ct++; + cost.cost = runtime; cost.complexity = complexity; @@ -2966,7 +2969,7 @@ get_computation_aff (struct loop *loop, tree common_type, var; tree uutype; aff_tree cbase_aff, var_aff; - double_int rat; + max_wide_int rat; if (TYPE_PRECISION (utype) > TYPE_PRECISION (ctype)) { @@ -3467,6 +3470,7 @@ get_shiftadd_cost (tree expr, enum machine_mode mode, comp_cost cost0, res = add_costs (res, force_expr_to_var_cost (multop, speed)); *cost = res; + return true; } @@ -3581,6 +3585,7 @@ force_expr_to_var_cost (tree expr, bool speed) break; default: + /* Just an arbitrary value, FIXME. */ return new_cost (target_spill_cost[speed], 0); } @@ -3603,7 +3608,7 @@ force_expr_to_var_cost (tree expr, bool speed) mult = op0; if (mult != NULL_TREE - && cst_and_fits_in_hwi (TREE_OPERAND (mult, 1)) + && cst_fits_shwi_p (TREE_OPERAND (mult, 1)) && get_shiftadd_cost (expr, mode, cost0, cost1, mult, speed, &sa_cost)) return sa_cost; @@ -3611,10 +3616,10 @@ force_expr_to_var_cost (tree expr, bool speed) break; case MULT_EXPR: - if (cst_and_fits_in_hwi (op0)) + if (cst_fits_shwi_p (op0)) cost = new_cost (mult_by_coeff_cost (int_cst_value (op0), mode, speed), 0); - else if (cst_and_fits_in_hwi (op1)) + else if (cst_fits_shwi_p (op1)) cost = new_cost (mult_by_coeff_cost (int_cst_value (op1), mode, speed), 0); else @@ -3734,7 +3739,7 @@ ptr_difference_cost (struct ivopts_data *data, type = signed_type_for (TREE_TYPE (e1)); tree_to_aff_combination (e1, type, &aff_e1); tree_to_aff_combination (e2, type, &aff_e2); - aff_combination_scale (&aff_e2, double_int_minus_one); + aff_combination_scale (&aff_e2, -1); aff_combination_add (&aff_e1, &aff_e2); return force_var_cost (data, aff_combination_to_tree (&aff_e1), depends_on); @@ -3789,7 +3794,7 @@ difference_cost (struct ivopts_data *data, type = signed_type_for (TREE_TYPE (e1)); tree_to_aff_combination (e1, type, &aff_e1); tree_to_aff_combination (e2, type, &aff_e2); - aff_combination_scale (&aff_e2, double_int_minus_one); + aff_combination_scale (&aff_e2, -1); aff_combination_add (&aff_e1, &aff_e2); return force_var_cost (data, aff_combination_to_tree (&aff_e1), depends_on); @@ -3908,16 +3913,16 @@ get_loop_invariant_expr_id (struct ivopts_data *data, tree ubase, { tree ind = TREE_OPERAND (usym, 1); if (TREE_CODE (ind) == INTEGER_CST - && host_integerp (ind, 0) - && TREE_INT_CST_LOW (ind) == 0) + && tree_fits_shwi_p (ind) + && tree_to_shwi (ind) == 0) usym = TREE_OPERAND (usym, 0); } if (TREE_CODE (csym) == ARRAY_REF) { tree ind = TREE_OPERAND (csym, 1); if (TREE_CODE (ind) == INTEGER_CST - && host_integerp (ind, 0) - && TREE_INT_CST_LOW (ind) == 0) + && tree_fits_shwi_p (ind) + && tree_to_shwi (ind) == 0) csym = TREE_OPERAND (csym, 0); } if (operand_equal_p (usym, csym, 0)) @@ -3933,7 +3938,7 @@ get_loop_invariant_expr_id (struct ivopts_data *data, tree ubase, tree_to_aff_combination (ub, TREE_TYPE (ub), &ubase_aff); tree_to_aff_combination (cb, TREE_TYPE (cb), &cbase_aff); - aff_combination_scale (&cbase_aff, double_int::from_shwi (-1 * ratio)); + aff_combination_scale (&cbase_aff, -1 * ratio); aff_combination_add (&ubase_aff, &cbase_aff); expr = aff_combination_to_tree (&ubase_aff); return get_expr_id (data, expr); @@ -3963,7 +3968,7 @@ get_computation_cost_at (struct ivopts_data *data, HOST_WIDE_INT ratio, aratio; bool var_present, symbol_present, stmt_is_after_inc; comp_cost cost; - double_int rat; + max_wide_int rat; bool speed = optimize_bb_for_speed_p (gimple_bb (at)); enum machine_mode mem_mode = (address_p ? TYPE_MODE (TREE_TYPE (*use->op_p)) @@ -4014,7 +4019,7 @@ get_computation_cost_at (struct ivopts_data *data, redundancy elimination is likely to transform the code so that it uses value of the variable before increment anyway, so it is not that much unrealistic. */ - if (cst_and_fits_in_hwi (cstep)) + if (cst_fits_shwi_p (cstep)) cstepi = int_cst_value (cstep); else cstepi = 0; @@ -4022,7 +4027,7 @@ get_computation_cost_at (struct ivopts_data *data, if (!constant_multiple_of (ustep, cstep, &rat)) return infinite_cost; - if (rat.fits_shwi ()) + if (wi::fits_shwi_p (rat)) ratio = rat.to_shwi (); else return infinite_cost; @@ -4039,7 +4044,7 @@ get_computation_cost_at (struct ivopts_data *data, (also holds in the case ratio == -1, TODO. */ - if (cst_and_fits_in_hwi (cbase)) + if (cst_fits_shwi_p (cbase)) { offset = - ratio * int_cst_value (cbase); cost = difference_cost (data, @@ -4294,7 +4299,7 @@ iv_period (struct iv *iv) period = build_low_bits_mask (type, (TYPE_PRECISION (type) - - tree_low_cst (pow2div, 1))); + - tree_to_uhwi (pow2div))); return period; } @@ -4492,7 +4497,7 @@ iv_elimination_compare_lt (struct ivopts_data *data, /* We need to be able to decide whether candidate is increasing or decreasing in order to choose the right comparison operator. */ - if (!cst_and_fits_in_hwi (cand->iv->step)) + if (!cst_fits_shwi_p (cand->iv->step)) return false; step = int_cst_value (cand->iv->step); @@ -4532,11 +4537,11 @@ iv_elimination_compare_lt (struct ivopts_data *data, tree_to_aff_combination (niter->niter, nit_type, &nit); tree_to_aff_combination (fold_convert (nit_type, a), nit_type, &tmpa); tree_to_aff_combination (fold_convert (nit_type, b), nit_type, &tmpb); - aff_combination_scale (&nit, double_int_minus_one); - aff_combination_scale (&tmpa, double_int_minus_one); + aff_combination_scale (&nit, -1); + aff_combination_scale (&tmpa, -1); aff_combination_add (&tmpb, &tmpa); aff_combination_add (&tmpb, &nit); - if (tmpb.n != 0 || tmpb.offset != double_int_one) + if (tmpb.n != 0 || tmpb.offset != 1) return false; /* Finally, check that CAND->IV->BASE - CAND->IV->STEP * A does not @@ -4622,13 +4627,13 @@ may_eliminate_iv (struct ivopts_data *data, entire loop and compare against that instead. */ else { - double_int period_value, max_niter; + max_wide_int period_value, max_niter; max_niter = desc->max; if (stmt_after_increment (loop, cand, use->stmt)) - max_niter += double_int_one; - period_value = tree_to_double_int (period); - if (max_niter.ugt (period_value)) + max_niter += 1; + period_value = period; + if (wi::gtu_p (max_niter, period_value)) { /* See if we can take advantage of inferred loop bound information. */ if (data->loop_single_exit_p) @@ -4636,7 +4641,7 @@ may_eliminate_iv (struct ivopts_data *data, if (!max_loop_iterations (loop, &max_niter)) return false; /* The loop bound is already adjusted by adding 1. */ - if (max_niter.ugt (period_value)) + if (wi::gtu_p (max_niter, period_value)) return false; } else @@ -4644,6 +4649,8 @@ may_eliminate_iv (struct ivopts_data *data, } } + static int cnt = 0; + cnt++; cand_value_at (loop, cand, use->stmt, desc->niter, &bnd); *bound = aff_combination_to_tree (&bnd); |