On 8/31/26 3:48 AM, Bohan Lei wrote:
In riscv_register_move_cost, the function
`riscv_secondary_memory_needed` call is at the end, and has no impact on
the early-returned values. Even if the move has to go through memory,
the register move cost is still used, which can lead to suboptimal code
generation, and even crashes.
Actually the current testcase can lead to an ICE without the patch when
using `-mtune=xt-c9501fdvt`, whose `fmv_cost` is 2 at present. I didn't
write that in the testcase as the fmv_cost being 2 does not correctly
reflect our design and we may change it in the future, in a separate
patch.
Regtested on rv64gcv and rv32gcv, no regression.
gcc/ChangeLog:
* config/riscv/riscv.cc (riscv_register_move_cost): Check
secondary memory necessity before early return.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rv32-fmv-cost-memory.c: New test.
OK for the trunk. Thanks.
jeff