]> git.ipfire.org Git - thirdparty/gcc.git/commit
[RISC-V] Avoid most calls to gen_extend_insn
authorJeff Law <jlaw@ventanamicro.com>
Sat, 15 Nov 2025 16:26:25 +0000 (09:26 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Sat, 15 Nov 2025 16:26:25 +0000 (09:26 -0700)
commit1569b0ad0e5a6b4d94d28fd9feffc6ae6ff3afdf
tree3f8e141cab34322d85c04da60f00d55252ff40b6
parent77705b475df4e4eed5831bf27e37250db2135fc8
[RISC-V] Avoid most calls to gen_extend_insn

Yet more infrastructure on our way to eliminating some define_insn_and_split
constructs.

The RISC-V port is using gen_extend_insn to directly generate a SIGN or ZERO
extend insn.  This is undesirable because we don't actually have a full set of
extension instructions, particularly zero extension for the base architecture.

We've gotten away with this because we've had a define_insn_and_splits which
claim to support the full set of zero/sign extensions.  We very much want to
eliminate that little white lie.  So we need to fix those pesky calls to
gen_extend_insn.

Similar to a patch from earlier this week convert_modes comes to the rescue.
It'll run through the expander path allowing us to generate the desired code.
In most cases it's a trivial replacement.

One case is left in the tree.  For that case the source operand is known to be
a MEM and we can always extend a load from a MEM.  Converting this one would
result in infinite recursion through riscv_legitimize_move.

One case is perhaps nontrivial.  convert_move will emit the code to perform the
conversion into a fresh pseudo register.  In one case we need to make sure that
value is copied into the output register for an insn.  So a trivial
emit_move_insn is needed.

Built and regression tested on riscv32-elf and riscv64-elf.  It's also
bootstrapped on the Pioneer.  Regression testing is in progress, but won't
finish for many hours.  The BPI is spinning this change right now, but won't
have results until tomorrow night.

gcc/
* config/riscv/riscv.cc (risc_legitimize_move): Use convert_modes
rather than gen_extend_insn for most cases.
* config/riscv/riscv.md (addv<mode>4): Likewise.
(uaddv<mode>4, subv<mode>4, usubv<mode>4): Likewise.
(mulv<mode>4, umulv<mode>4): Likewise.
* config/riscv/sync.md (atomic_compare_and_swap<mode>): Likewise.
gcc/config/riscv/riscv.cc
gcc/config/riscv/riscv.md
gcc/config/riscv/sync.md