Skip to content

Commit 3b90124

Browse files
artemiy-volkovMichielDerhaeg
authored andcommitted
arcv: fuse integer multiply-add instruction pairs
To make sure that the multiply-add pairs (split post-reload from the madd_split instruction) are not broken up by the sched2 pass, designate them as fusable in arcv_macro_fusion_pair_p (). Signed-off-by: Artemiy Volkov <artemiy@synopsys.com>
1 parent 8cd7eef commit 3b90124

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

gcc/config/riscv/arcv-rhx100.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
condmove,mvpair,zicond,cpop,clmul"))
4343
"((arcv_rhx100_issueA_fuse0 + arcv_rhx100_ALU_A_fuse0_early) | (arcv_rhx100_issueA_fuse1 + arcv_rhx100_ALU_A_fuse1_early)) | ((arcv_rhx100_issueB_fuse0 + arcv_rhx100_ALU_B_fuse0_early) | (arcv_rhx100_issueB_fuse1 + arcv_rhx100_ALU_B_fuse1_early))")
4444

45+
(define_insn_reservation "arcv_rhx100_imul_fused" 4
46+
(and (eq_attr "tune" "arcv_rhx100")
47+
(eq_attr "type" "imul_fused"))
48+
"(arcv_rhx100_issueA_fuse0 + arcv_rhx100_issueA_fuse1 + arcv_rhx100_ALU_A_fuse0_early + arcv_rhx100_ALU_A_fuse1_early + arcv_rhx100_MPY32), nothing*3")
49+
4550
(define_insn_reservation "arcv_rhx100_jmp_insn" 1
4651
(and (eq_attr "tune" "arcv_rhx100")
4752
(eq_attr "type" "branch,jump,call,jalr,ret,trap"))

gcc/config/riscv/riscv.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10564,6 +10564,13 @@ arcv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
1056410564
&& SET_DEST (prev_set) == SUBREG_REG (SET_SRC (curr_set)))))
1056510565
return true;
1056610566

10567+
if (GET_CODE (SET_SRC (prev_set)) == MULT
10568+
&& GET_CODE (SET_SRC (curr_set)) == PLUS
10569+
&& REGNO (SET_DEST (prev_set)) == REGNO (SET_DEST (curr_set))
10570+
&& (REGNO (SET_DEST (prev_set)) == REGNO (XEXP (SET_SRC (curr_set), 0))
10571+
|| REGNO (SET_DEST (prev_set)) == REGNO (XEXP (SET_SRC (curr_set), 1))))
10572+
return true;
10573+
1056710574
return false;
1056810575
}
1056910576

gcc/config/riscv/riscv.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@
518518
vslideup,vslidedown,vislide1up,vislide1down,vfslide1up,vfslide1down,
519519
vgather,vcompress,vmov,vector,vandn,vbrev,vbrev8,vrev8,vclz,vctz,vcpop,vrol,vror,vwsll,
520520
vclmul,vclmulh,vghsh,vgmul,vaesef,vaesem,vaesdf,vaesdm,vaeskf1,vaeskf2,vaesz,
521-
vsha2ms,vsha2ch,vsha2cl,vsm4k,vsm4r,vsm3me,vsm3c,vfncvtbf16,vfwcvtbf16,vfwmaccbf16,
521+
vsha2ms,vsha2ch,vsha2cl,vsm4k,vsm4r,vsm3me,vsm3c,vfncvtbf16,vfwcvtbf16,vfwmaccbf16,imul_fused,
522522
sf_vc,sf_vc_se"
523523
(cond [(eq_attr "got" "load") (const_string "load")
524524

@@ -4552,7 +4552,7 @@
45524552
rtx tmp0 = gen_reg_rtx (SImode), tmp1 = gen_reg_rtx (SImode);
45534553
emit_insn (gen_zero_extendhisi2 (tmp0, operands[1]));
45544554
emit_insn (gen_zero_extendhisi2 (tmp1, operands[2]));
4555-
emit_insn (gen_madd_split (operands[0], tmp0, tmp1, operands[3]));
4555+
emit_insn (gen_madd_split_fused (operands[0], tmp0, tmp1, operands[3]));
45564556
DONE;
45574557
}
45584558
)
@@ -4566,31 +4566,26 @@
45664566
"TARGET_XTHEADMAC"
45674567
)
45684568

4569-
(define_insn_and_split "madd_split"
4569+
(define_insn "madd_split_fused"
45704570
[(set (match_operand:SI 0 "register_operand" "=&r,r")
45714571
(plus:SI
45724572
(mult:SI (match_operand:SI 1 "register_operand" "r,r")
45734573
(match_operand:SI 2 "register_operand" "r,r"))
45744574
(match_operand:SI 3 "register_operand" "r,?0")))
45754575
(clobber (match_scratch:SI 4 "=&r,&r"))]
4576-
"riscv_is_micro_arch (rhx) && !TARGET_64BIT && (TARGET_ZMMUL || TARGET_MUL)"
4577-
"#"
4578-
"&& reload_completed"
4579-
[(const_int 0)]
4580-
"{
4576+
"riscv_is_micro_arch (arcv_rhx100)
4577+
&& !TARGET_64BIT && (TARGET_ZMMUL || TARGET_MUL)"
4578+
{
45814579
if (REGNO (operands[0]) == REGNO (operands[3]))
45824580
{
4583-
emit_insn (gen_mulsi3 (operands[4], operands[1], operands[2]));
4584-
emit_insn (gen_addsi3 (operands[0], operands[3], operands[4]));
4581+
return "mul\t%4,%1,%2\n\tadd\t%4,%3,%4\n\tmv\t%0,%4";
45854582
}
45864583
else
45874584
{
4588-
emit_insn (gen_mulsi3 (operands[0], operands[1], operands[2]));
4589-
emit_insn (gen_addsi3 (operands[0], operands[0], operands[3]));
4585+
return "mul\t%0,%1,%2\n\tadd\t%0,%0,%3";
45904586
}
4591-
DONE;
4592-
}"
4593-
[(set_attr "type" "imul")]
4587+
}
4588+
[(set_attr "type" "imul_fused")]
45944589
)
45954590

45964591
;; String compare with length insn.

0 commit comments

Comments
 (0)