Skip to content

Commit 8bf79f3

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 32300a0 commit 8bf79f3

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
@@ -11191,6 +11191,13 @@ arcv_macro_fusion_pair_p (rtx_insn *prev, rtx_insn *curr)
1119111191
&& SET_DEST (prev_set) == SUBREG_REG (SET_SRC (curr_set)))))
1119211192
return true;
1119311193

11194+
if (GET_CODE (SET_SRC (prev_set)) == MULT
11195+
&& GET_CODE (SET_SRC (curr_set)) == PLUS
11196+
&& REGNO (SET_DEST (prev_set)) == REGNO (SET_DEST (curr_set))
11197+
&& (REGNO (SET_DEST (prev_set)) == REGNO (XEXP (SET_SRC (curr_set), 0))
11198+
|| REGNO (SET_DEST (prev_set)) == REGNO (XEXP (SET_SRC (curr_set), 1))))
11199+
return true;
11200+
1119411201
return false;
1119511202
}
1119611203

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

@@ -4528,7 +4528,7 @@
45284528
rtx tmp0 = gen_reg_rtx (SImode), tmp1 = gen_reg_rtx (SImode);
45294529
emit_insn (gen_zero_extendhisi2 (tmp0, operands[1]));
45304530
emit_insn (gen_zero_extendhisi2 (tmp1, operands[2]));
4531-
emit_insn (gen_madd_split (operands[0], tmp0, tmp1, operands[3]));
4531+
emit_insn (gen_madd_split_fused (operands[0], tmp0, tmp1, operands[3]));
45324532
DONE;
45334533
}
45344534
)
@@ -4542,31 +4542,26 @@
45424542
"TARGET_XTHEADMAC"
45434543
)
45444544

4545-
(define_insn_and_split "madd_split"
4545+
(define_insn "madd_split_fused"
45464546
[(set (match_operand:SI 0 "register_operand" "=&r,r")
45474547
(plus:SI
45484548
(mult:SI (match_operand:SI 1 "register_operand" "r,r")
45494549
(match_operand:SI 2 "register_operand" "r,r"))
45504550
(match_operand:SI 3 "register_operand" "r,?0")))
45514551
(clobber (match_scratch:SI 4 "=&r,&r"))]
4552-
"riscv_is_micro_arch (rhx) && !TARGET_64BIT && (TARGET_ZMMUL || TARGET_MUL)"
4553-
"#"
4554-
"&& reload_completed"
4555-
[(const_int 0)]
4556-
"{
4552+
"riscv_is_micro_arch (arcv_rhx100)
4553+
&& !TARGET_64BIT && (TARGET_ZMMUL || TARGET_MUL)"
4554+
{
45574555
if (REGNO (operands[0]) == REGNO (operands[3]))
45584556
{
4559-
emit_insn (gen_mulsi3 (operands[4], operands[1], operands[2]));
4560-
emit_insn (gen_addsi3 (operands[0], operands[3], operands[4]));
4557+
return "mul\t%4,%1,%2\n\tadd\t%4,%3,%4\n\tmv\t%0,%4";
45614558
}
45624559
else
45634560
{
4564-
emit_insn (gen_mulsi3 (operands[0], operands[1], operands[2]));
4565-
emit_insn (gen_addsi3 (operands[0], operands[0], operands[3]));
4561+
return "mul\t%0,%1,%2\n\tadd\t%0,%0,%3";
45664562
}
4567-
DONE;
4568-
}"
4569-
[(set_attr "type" "imul")]
4563+
}
4564+
[(set_attr "type" "imul_fused")]
45704565
)
45714566

45724567
;; String compare with length insn.

0 commit comments

Comments
 (0)