On 11/10/26 7:15 PM, Bohan Lei wrote:
This is based on Zhijin Zeng's v3 patch
(https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673406.html).
This commit modifies riscv_can_change_mode_class and
riscv_hard_regno_mode_ok to allow IRA to allocate an FPR to a pseudo
that is used in a interger mode in some places.

A typical scenario would be cases with bit-level uses of floating-point
variables.  The current IRA can only allocate them in GPRs, and any FP
use of it would create a new FPR reload, which can lead to lots of
redundant fmv.d.x instructions in the function.  The attached case
(LLM-generated) is a reduced one that can still show the underlying
issue.

I am not using Zhijin's original testcase in this version because
register renaming has accidentally helped eliminate the redundant fmv
instructions in that case.

Also note that the tiebility change in that patch is not included in
this version.  We found that change can lead to more regressions and
would require special handling.  Nonetheless, we found one redundant
fmv.x.d instruction in our complete lgamma case downstream, not verified
with the trunk though, which can be eliminated with the tieability
change.  (After all, FP and integer modes being tieable makes it hard
track separate live ranges of integer uses and FP uses of the same
variable.)  We may submit a separate tieability patch after gathering
enough evidence that this could lead to real performance issues.

The earlier version failed to handle xtheadfmemidx correctly, and this
version contains a fix for that route.  A local Sashiko review found a
preexisting issue in th_memidx_classify_address_index, for which after
confirming I will send a separate patch as it is not directly related to
this.

Regtested on rv64gcv and rv32gcv, no regression.

Assisted-by: Codex
Co-authored-by: Zhijin Zeng <[email protected]>

gcc/ChangeLog:

        * config/riscv/constraints.md (th_m_fpr): New constraint for FPR
        load/store.
        * config/riscv/riscv.cc (riscv_hard_regno_mode_ok): Allow SImode
        and DImode in GPRs.
        (riscv_can_change_mode_class): Allow mode changing between
        integer and FP modes.
        * config/riscv/riscv.md: Add f,f constraints to SI and HI moves.
        * config/riscv/thead.cc (th_fmemidx_output_index): Take into
        account the scenario where MODE is integral.
        (th_output_move): Remove instruction class conditions.
        * config/riscv/vector.md: Restore X constraint for vr,vr LRA
        move patterns to prevent ICE caused by FPR-allocated scratch.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/fmv-lgamma.c: New test.
        * gcc.target/riscv/xtheadmemidx-fpr-int-1.c: New test.
        * gcc.target/riscv/xtheadmemidx-fpr-int-2.c: New test.
        * gcc.target/riscv/xtheadmemidx-fpr-int.h: New test.
Sigh.  I'm not happy with the movXX pattern changes, though I'm not too surprised by them either.

In the old reload days movXX was highly special and you weren't allowed to have distinct patterns that implemented movXX semantics. So for example if you had a separate load insn which allowed special addressing modes, you'd eventually get a failure in reload.  The details have gotten incredibly fuzzy but it was a huge source of problems when supporting the scaled and unscaled addressing modes on the PA chip eons ago.

I've never been 100% sure if that requirement carried over to the LRA world, but this patch seems to be starting to touch on the same area.

Can you describe exactly why you made those movXX changes?  This is mostly so I can ponder if we have a more general problem, particularly with the scaled/unscaled indexed addressing modes available on the thead designs and soon with Zilx.

Neither an ACK nor a NAK at this time.

Jeff

Reply via email to