On 11/10/22 07:37, Lin Sinan via Gcc-patches wrote: > The motivation of this patch is to correct the wrong estimation of the number of instructions needed for loading a 64bit constant in rv32 in the current cost model(riscv_interger_cost). According to the current implementation, if a constant requires more than 3 instructions(riscv_const_insn and riscv_legitimate_constant_p), then the constant will be put into constant pool when expanding gimple to rtl(legitimate_constant_p hook and emit_move_insn). So the inaccurate cost model leads to the suboptimal codegen in rv32 and the wrong estimation part could be corrected through this fix. > > e.g. the current codegen for loading 0x839290001 in rv32 > > lui a5,%hi(.LC0) > lw a0,%lo(.LC0)(a5) > lw a1,%lo(.LC0+4)(a5) > .LC0: > .word 958988289 > .word 8 > > output after this patch > > li a0,958988288 > addi a0,a0,1 > li a1,8 > > gcc/ChangeLog: > > * config/riscv/riscv.cc (riscv_build_integer): Handle the case of loading 64bit constant in rv32. > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/rv32-load-64bit-constant.c: New test. > > Signed-off-by: Lin Sinan I fixed up the ChangeLog and some minor formatting issues in the new code in riscv_build_integer. I also twiddled the test so that it iterates over the optimization levels properly while skipping -O0. Attached is the patch I committed. jeff