Re: [PATCH v3 2/3] ivopts: Remove target_reg_cost from reg pressure estimate.
Richard Biener <[email protected]>
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <CAFiYyc0hz4Gg-JsLa7geB4KXmZVACeQ-4GWP-D8_ZpyfewAjEQ@mail.gmail.com> |
On Wed, Jul 29, 2026 at 4:01 PM Jovan Dmitrovic <[email protected]> wrote: > > The target_reg_cost plays a large part in the estimated cost for > register pressure, but it should be the eventual spilling that > has the most influence on the cost of storing/loading IV candidates and > invariants. > > gcc/ChangeLog: > > * tree-ssa-loop-ivopts.cc (ivopts_estimate_reg_pressure): > Remove target_reg_cost from the computation of register pressure. > > Signed-off-by: Jovan Dmitrović <[email protected]> > --- > gcc/tree-ssa-loop-ivopts.cc | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) > > diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc > index 72f801a6fd89..ca06592190e0 100644 > --- a/gcc/tree-ssa-loop-ivopts.cc > +++ b/gcc/tree-ssa-loop-ivopts.cc > @@ -6093,22 +6093,17 @@ ivopts_estimate_reg_pressure (struct ivopts_data *data, unsigned n_invs, > available_regs = available_regs - target_clobbered_regs; > > /* If we have enough registers. */ > - if (regs_needed + target_res_regs < available_regs) > + if (regs_needed <= available_regs) > cost = 0; > - /* If close to running out of registers, try to preserve them. */ > - else if (regs_needed <= available_regs) > - cost = target_reg_cost [speed] * regs_needed; So this already does two things - it changes "when we have enough registers", excluding target_res_regs ("reserved for temporaries", constant 3(!)), and the main part is that it does not cost "using a register" as cost. I'm not sure why we factored in reg-reg move costs, so I think removing makes sense. If an addressing mode requires a fixed register to be used then the AGU cost should include a move. I think the patch is OK but please update the description and the ChangeLog to mention you remove the target_res_regs "lose matching" of having enough registers. IMO for consistency, if we want to preserve that, we should update 'regs_needed' with that. Thanks, Richard. > /* If we run out of available registers but the number of candidates > does not, we penalize extra registers using target_spill_cost. */ > else if (n_cands <= available_regs) > - cost = target_reg_cost [speed] * available_regs > - + target_spill_cost [speed] * (regs_needed - available_regs); > + cost = target_spill_cost [speed] * (regs_needed - available_regs); > /* If the number of candidates runs out available registers, we penalize > extra candidate registers using target_spill_cost * 2. Because it is > more expensive to spill induction variable than invariant. */ > else > - cost = target_reg_cost [speed] * available_regs > - + target_spill_cost [speed] * (n_cands - available_regs) * 2 > + cost = target_spill_cost [speed] * (n_cands - available_regs) * 2 > + target_spill_cost [speed] * (regs_needed - n_cands); > > return cost; > -- > 2.34.1