Hi!

On Sat, Nov 15, 2025 at 09:51:17AM -0700, Jeff Law wrote:
>       * config/riscv/riscv.cc (riscv_rtx_costs): Properly cost pack insns
>       for Zbkb.

You are way way way better off if you would use insn_cost instead -- it
even actually makes sense (rtx_costs is pretty much meaningless).

Even with a bloody stupid implementation (just count the number of
instruction bytes) you'll likely get better results already.  And, way
more maintainable code as well!

Actually costing the generated code (by looking at the actually generated
insns) is much more direct, and much more effective than inventing some
cost for some RTL expression.

For rs6000 for example we have a pretty simple cost function: if an insn
has a "cost" attribute, use what it says.  (We actually use it in one
place in the rs6000 backend, to work around another limitation of RTL).
Otherwise, we want to know the number of generated insns.  We either get
that from the "num_insns" attribute, or try to derive it from the insn
length and if it is a prefixed insn or not.
Most insns cost the same.  Load insns are a bit more expensive (this is
traditional in GCC, rtx_costs does the same, you get better end results
with this).  Mul and div is a bit more expensive, FP too, and "special"
insns are a bit, well, "special".
And that's about it.

There still are a few places that call rtx_costs, but fewer and fewer.


Segher

Reply via email to