Message ID | 15644575.zb4QZkAvgm@polaris |
---|---|
State | New |
Headers | show |
On 02/05/15 08:53, Eric Botcazou wrote: > Hi, > > this is the failure of gcc.dg/tree-ssa/ivopts-lt-2.c on SPARC 64-bit, but I > think that the problem is actually generic: get_shiftadd_cost only calls > shiftadd_cost to get the cost of a "shift-add", which is actually a multiply > by a power-of-2 operation. Since SPARC doesn't have a lea-like instruction, > shiftadd_cost returns a very high cost, about 3 times the cost of an add+shift > sequence which is what the RTL expander will generate for this operation. > > So I think that get_shiftadd_cost should mimic the algorithms in expmed.c and > use the minimum of shiftadd_cost and (add_cost + shift_cost) for the cost of > the shift-add operation. > > Tested on x86-64, SPARC and SPARC64, OK for the mainline? > > > 2015-02-05 Eric Botcazou <ebotcazou@adacore.com> > > PR target/62631 > * tree-ssa-loop-ivopts.c (get_shiftadd_cost): Use the mininum of costs > of shift-add and (add + shift) operations. Rename local variable. OK jeff
--- tree-ssa-loop-ivopts.c (revision 220343) +++ tree-ssa-loop-ivopts.c (working copy) @@ -3597,22 +3597,26 @@ get_shiftadd_cost (tree expr, machine_mo tree multop = TREE_OPERAND (mult, 0); int m = exact_log2 (int_cst_value (cst)); int maxm = MIN (BITS_PER_WORD, GET_MODE_BITSIZE (mode)); - int sa_cost; - bool equal_p = false; + int as_cost, sa_cost; + bool mult_in_op1; if (!(m >= 0 && m < maxm)) return false; - if (operand_equal_p (op1, mult, 0)) - equal_p = true; + mult_in_op1 = operand_equal_p (op1, mult, 0); + as_cost = add_cost (speed, mode) + shift_cost (speed, mode, m); + + /* If the target has a cheap shift-and-add or shift-and-sub instruction, + use that in preference to a shift insn followed by an add insn. */ sa_cost = (TREE_CODE (expr) != MINUS_EXPR ? shiftadd_cost (speed, mode, m) - : (equal_p + : (mult_in_op1 ? shiftsub1_cost (speed, mode, m) : shiftsub0_cost (speed, mode, m))); - res = new_cost (sa_cost, 0); - res = add_costs (res, equal_p ? cost0 : cost1); + + res = new_cost (MIN (as_cost, sa_cost), 0); + res = add_costs (res, mult_in_op1 ? cost0 : cost1); STRIP_NOPS (multop); if (!is_gimple_val (multop))