On 11/16/26 1:57 AM, Bohan Lei wrote:
This commit tries hoist VXRM writes to preheaders on microarchs that
have a pipeline flush on such CSR write.  The main motivation of this
patch is x264, as after the LTO patches, some get_ref related functions
get inlined into callers and VXRM can no longer be hoisted to the
function epilogue.  This version currently only handles those in
innermost loops.  The tuning parameters are added as per the LLVM
handling of the similar optimization.

Related testcases were run manually.  Regression tests on rv64gcv and
rv32gcv in flight.

gcc/ChangeLog:

        * config/riscv/riscv-protos.h (riscv_optimize_mode_switching): Declare.
        * config/riscv/riscv.cc (struct machine_function): Add loop
        requirement cache.
        (struct riscv_tune_param): Add vxrm_pipeline_flush.
        (generic_tune_info): Initialize vxrm_pipeline_flush.
        (rocket_tune_info): Ditto.
        (sifive_7_tune_info): Ditto.
        (sifive_p400_tune_info): Ditto.
        (sifive_p600_tune_info): Ditto.
        (sifive_p550_tune_info): Ditto.
        (sifive_p870_tune_info): Ditto.
        (thead_c906_tune_info): Ditto.
        (xiangshan_nanhu_tune_info): Ditto.
        (generic_ooo_tune_info): Ditto.
        (xt_c9501_tune_info): Ditto.
        (tt_ascalon_d8_tune_info): Ditto.
        (optimize_size_tune_info): Ditto.
        (mips_p8700_tune_info): Ditto.
        (mips_i8500_tune_info): Ditto.
        (andes_25_tune_info): Ditto.
        (xt_c908_tune_info): Ditto.
        (spacemit_x60_tune_info): Ditto.
        (spacemit_x100_tune_info): Ditto.
        (andes_23_tune_info): Ditto.
        (andes_45_tune_info): Ditto.
        (arcv_rhx100_tune_info): Ditto.
        (arcv_rmx100_tune_info): Ditto.
        (asm_insn_p): Move before riscv_vxrm_loop_safe_p.
        (vxrm_unknown_p): Ditto.
        (riscv_vxrm_loop_safe_p): New function.
        (riscv_vxrm_loop_requirements): Ditto.
        (riscv_optimize_mode_switching): Ditto.
        (riscv_mode_needed): Look up prepared loop requirements.
        * config/riscv/riscv.h (OPTIMIZE_MODE_SWITCHING): Call
        riscv_optimize_mode_switching.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/rvv/base/vxrm-loop-1.c: New test.
        * gcc.target/riscv/rvv/base/vxrm-loop-2.c: New test.
So to be more concrete.

We want to do the aggressive hoisting by pretending the first insn has a VXRM need, even if the function has calls.  What we want to know is whether or not there is a path from entry to each VXRM use point that does not pass through a call or otherwise clobbers VXRM. If there is any such path then pretend we have a VXRM demand on the first insn.

Calls clobber VXRM and will inherently trigger a restore of the value after the call if that point reaches a VXRM use point.

jeff


Reply via email to