https://gcc.gnu.org/g:146c81019b20e5c74c886a72fc5a1b29cf9767cd
commit r17-6403-g146c81019b20e5c74c886a72fc5a1b29cf9767cd Author: Jin Ma <[email protected]> Date: Wed Aug 12 19:01:58 2026 +0800 RISC-V: Add ascending floating-point load/store pair fusion Add a future-facing capability for adjacent single- or double-precision floating-point loads or stores whose addresses share a base and increase by one access size. Reuse the pair matcher shared with integer pairs. Leave the capability disabled and XFAIL its positive dump check. Assisted-by: qwenwork gcc/ChangeLog: * config/riscv/riscv-fusion.cc (riscv_fusion_mem_rules): Add RISCV_FUSE_FLDFST_PAIR_INC. (riscv_fuse_fldfst_pair_inc): New function. (riscv_fusion_table): Add RISCV_FUSE_FLDFST_PAIR_INC. * config/riscv/riscv-protos.h (enum riscv_fusion_pairs): Add RISCV_FUSE_FLDFST_PAIR_INC. gcc/testsuite/ChangeLog: * gcc.target/riscv/fusion-fldfst-pair-inc.c: New test. Signed-off-by: Jin Ma <[email protected]> Diff: --- gcc/config/riscv/riscv-fusion.cc | 26 ++++++++++++++++++ gcc/config/riscv/riscv-protos.h | 1 + .../gcc.target/riscv/fusion-fldfst-pair-inc.c | 31 ++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/gcc/config/riscv/riscv-fusion.cc b/gcc/config/riscv/riscv-fusion.cc index 43ae80c52062..9b857bc176c3 100644 --- a/gcc/config/riscv/riscv-fusion.cc +++ b/gcc/config/riscv/riscv-fusion.cc @@ -1019,6 +1019,10 @@ static const struct riscv_fusion_mem_rule riscv_fusion_mem_rules[] = { RISCV_FUSE_LDST_PAIR_DEC, (1U << 4) | (1U << 8), SCHED_FUSION_LD | SCHED_FUSION_LD_SIGN_EXTEND | SCHED_FUSION_ST, false, false, RISCV_FUSION_DEC, 1 }, + { RISCV_FUSE_FLDFST_PAIR_INC, (1U << 4) | (1U << 8), + SCHED_FUSION_LD | SCHED_FUSION_LD_SIGN_EXTEND + | SCHED_FUSION_LD_ZERO_EXTEND | SCHED_FUSION_ST, + true, false, RISCV_FUSION_INC, 1 }, /* Allow 1-, 2-, 4- and 8-byte stores. */ { RISCV_FUSE_ALIGNED_STD, (1U << 1) | (1U << 2) | (1U << 4) | (1U << 8), SCHED_FUSION_ST, false, true, RISCV_FUSION_ANY, 2 } @@ -1627,6 +1631,26 @@ riscv_fuse_ldst_pair_dec (rtx_insn *prev, rtx_insn *curr) return riscv_fuse_mem_pair_p (prev, curr, RISCV_FUSE_LDST_PAIR_DEC); } +/* Check for RISCV_FUSE_FLDFST_PAIR_INC fusion. + prev/curr (one of the following pairs): + prev (flw/fld) == (set (reg frd1) (mem (rs1, offset1))) + curr (flw/fld) == (set (reg frd2) (mem (rs1, offset2))) + + prev (fsw/fsd) == (set (mem (rs1, offset1)) (reg frs1)) + curr (fsw/fsd) == (set (mem (rs1, offset2)) (reg frs2)) + + Constraints: + access size is 4 or 8 bytes + offset2 - offset1 equals the access size + offsets are aligned to the access size + for loads, frd1 != frd2. */ + +static bool +riscv_fuse_fldfst_pair_inc (rtx_insn *prev, rtx_insn *curr) +{ + return riscv_fuse_mem_pair_p (prev, curr, RISCV_FUSE_FLDFST_PAIR_INC); +} + /* Check for RISCV_FUSE_BFEXT fusion. prev (slli) == (set (reg rd1) (ashift (reg rs1) (const_int shamt1))) @@ -1979,6 +2003,8 @@ static const struct riscv_fusion_entry riscv_fusion_table[] = riscv_fuse_ldst_pair_inc, "RISCV_FUSE_LDST_PAIR_INC" }, { RISCV_FUSE_LDST_PAIR_DEC, riscv_fuse_ldst_pair_dec, "RISCV_FUSE_LDST_PAIR_DEC" }, + { RISCV_FUSE_FLDFST_PAIR_INC, + riscv_fuse_fldfst_pair_inc, "RISCV_FUSE_FLDFST_PAIR_INC" }, { RISCV_FUSE_BFEXT, riscv_fuse_bfext, "RISCV_FUSE_BFEXT" }, { RISCV_FUSE_SLLI_SRLI, diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h index 680dd0b28719..272b9e6edba4 100644 --- a/gcc/config/riscv/riscv-protos.h +++ b/gcc/config/riscv/riscv-protos.h @@ -881,6 +881,7 @@ enum riscv_fusion_pairs RISCV_FUSE_POSTINDEX_ST = HOST_WIDE_INT_1U << 22, RISCV_FUSE_LDST_PAIR_INC = HOST_WIDE_INT_1U << 23, RISCV_FUSE_LDST_PAIR_DEC = HOST_WIDE_INT_1U << 24, + RISCV_FUSE_FLDFST_PAIR_INC = HOST_WIDE_INT_1U << 25, }; extern bool riscv_macro_fusion_p (void); diff --git a/gcc/testsuite/gcc.target/riscv/fusion-fldfst-pair-inc.c b/gcc/testsuite/gcc.target/riscv/fusion-fldfst-pair-inc.c new file mode 100644 index 000000000000..e74808c62bcd --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/fusion-fldfst-pair-inc.c @@ -0,0 +1,31 @@ +/* { dg-do compile { target { rv64 } } } */ +/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-O3" "-O[sgz]" "-flto" } } */ +/* { dg-options "-march=rv64gc -mabi=lp64d -mtune=xt-c9501fdvt -O2 -fdump-rtl-sched2-details" } */ +/* No tune enables RISCV_FUSE_FLDFST_PAIR_INC yet. */ +/* { dg-final { scan-rtl-dump-times "RISCV_FUSE_FLDFST_PAIR_INC" 4 "sched2" { xfail *-*-* } } } */ + +float +test_flw_pair_inc (float *p) +{ + return p[0] + p[1]; +} + +double +test_fld_pair_inc (double *p) +{ + return p[0] + p[1]; +} + +void +test_fsw_pair_inc (float *p, float a, float b) +{ + p[0] = a; + p[1] = b; +} + +void +test_fsd_pair_inc (double *p, double a, double b) +{ + p[0] = a; + p[1] = b; +}
