https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111139
Bug ID: 111139 Summary: RISC-V: improve scalar constants cost model Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: vineetg at gcc dot gnu.org CC: jeffreyalaw at gmail dot com, kito.cheng at gmail dot com, palmer at dabbelt dot com Target Milestone: --- The current const cost determination in riscv_rtx_costs () and its children such as riscv_const_insns () needs improvements. 1. There's some likely inaccuracies with various heuristics. 2. Those heuristics are distributed in a bunch of places and better be consolidated. 3. We need to make const cost cpu/uarch tunable as hardware widgets like macro fusions could ammortize multi-insn const costs. Some of the heuristics to cleanup/revisit: 1a. riscv_rtx_cost() returns 1 insn even if riscv_const_insns () returns > 1. case CONST: if ((cost = riscv_const_insns (x)) > 0) { if (cost == 1 && outer_code == SET) *total = COSTS_N_INSNS (1); else if (outer_code == SET || GET_MODE (x) == VOIDmode) *total = COSTS_N_INSNS (1); } 1b. riscv_const_insns () caps the const cost to 4 even if it higher with intent to force const pool. RV backend in general no longer favors const pools for large constants since 2e886eef7f2b5a ("RISC-V: Produce better code with complex constants [PR95632] [PR106602]"). This heuristic needs to be revisited. 1c. riscv_split_integer_cost () adds 2 to initial cost computed.