Skip to content

Commit b17f2f1

Browse files
AinsleySnowimkiva
authored andcommitted
[LLVM][XTHeadVector] Implement intrinsics for vmacc/vnmsac/vmadd/vnmsub. (llvm#66)
* [LLVM][XTHeadVector] Define intrinsics. * [LLVM][XTHeadVector] Define pseudos and pats. * [LLVM][XTHeadVector] Add test cases. * [NFC][XTHeadVector] Update README.
1 parent 7f09bca commit b17f2f1

File tree

7 files changed

+7882
-0
lines changed

7 files changed

+7882
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Any feature not listed below but present in the specification should be consider
4848
- (Done) `12.8. Vector Integer Min/Max Instructions`
4949
- (Done) `12.10. Vector Integer Divide Instructions`
5050
- (Done) `12.11. Vector Widening Integer Multiply Instructions`
51+
- (Done) `12.12. Vector Single-Width Integer Multiply-Add Instructions`
5152
- (WIP) Clang intrinsics related to the `XTHeadVector` extension:
5253
- (WIP) `6. Configuration-Setting and Utility`
5354
- (Done) `6.1. Set vl and vtype`

llvm/include/llvm/IR/IntrinsicsRISCVXTHeadV.td

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,27 @@ let TargetPrefix = "riscv" in {
612612
let VLOperand = 4;
613613
}
614614

615+
// UnMasked Vector Multiply-Add operations, its first operand can not be undef.
616+
// Input: (vector_in, vector_in/scalar, vector_in, vl)
617+
class XVTernaryAAXAUnMasked
618+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
619+
[LLVMMatchType<0>, llvm_any_ty, LLVMMatchType<0>,
620+
llvm_anyint_ty], [IntrNoMem]>, RISCVVIntrinsic {
621+
let ScalarOperand = 1;
622+
let VLOperand = 3;
623+
}
624+
625+
// Masked Vector Multiply-Add operations, its first operand can not be undef.
626+
// Input: (vector_in, vector_in/scalar, vector_in, mask, vl)
627+
class XVTernaryAAXAMasked
628+
: DefaultAttrsIntrinsic<[llvm_anyvector_ty],
629+
[LLVMMatchType<0>, llvm_any_ty, LLVMMatchType<0>,
630+
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
631+
llvm_anyint_ty], [IntrNoMem]>, RISCVVIntrinsic {
632+
let ScalarOperand = 1;
633+
let VLOperand = 4;
634+
}
635+
615636
multiclass XVBinaryAAX {
616637
def "int_riscv_" # NAME : RISCVBinaryAAXUnMasked;
617638
def "int_riscv_" # NAME # "_mask" : XVBinaryAAXMasked;
@@ -631,6 +652,11 @@ let TargetPrefix = "riscv" in {
631652
def "int_riscv_" # NAME : RISCVBinaryABShiftUnMasked;
632653
def "int_riscv_" # NAME # "_mask" : XVBinaryABShiftMasked;
633654
}
655+
656+
multiclass XVTernaryAAXA {
657+
def "int_riscv_" # NAME : XVTernaryAAXAUnMasked;
658+
def "int_riscv_" # NAME # "_mask" : XVTernaryAAXAMasked;
659+
}
634660
}
635661

636662
let TargetPrefix = "riscv" in {
@@ -698,6 +724,12 @@ let TargetPrefix = "riscv" in {
698724
defm th_vwmul : XVBinaryABX;
699725
defm th_vwmulu : XVBinaryABX;
700726
defm th_vwmulsu : XVBinaryABX;
727+
728+
// 12.12. Vector Single-Width Integer Multiply-Add Instructions
729+
defm th_vmacc : XVTernaryAAXA;
730+
defm th_vnmsac : XVTernaryAAXA;
731+
defm th_vmadd : XVTernaryAAXA;
732+
defm th_vnmsub : XVTernaryAAXA;
701733
} // TargetPrefix = "riscv"
702734

703735
let TargetPrefix = "riscv" in {

llvm/lib/Target/RISCV/RISCVInstrInfoXTHeadVPseudos.td

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,23 @@ class XVPseudoTiedBinaryMask<VReg RetClass,
15841584
let IsTiedPseudo = 1;
15851585
}
15861586

1587+
class XVPseudoBinaryMaskNoPolicy<VReg RetClass,
1588+
RegisterClass Op1Class,
1589+
DAGOperand Op2Class,
1590+
string Constraint> :
1591+
Pseudo<(outs GetVRegNoV0<RetClass>.R:$rd),
1592+
(ins GetVRegNoV0<RetClass>.R:$merge,
1593+
Op1Class:$rs2, Op2Class:$rs1,
1594+
VMaskOp:$vm, AVL:$vl, ixlenimm:$sew), []>,
1595+
RISCVVPseudo {
1596+
let mayLoad = 0;
1597+
let mayStore = 0;
1598+
let hasSideEffects = 0;
1599+
let Constraints = !interleave([Constraint, "$rd = $merge"], ",");
1600+
let HasVLOp = 1;
1601+
let HasSEWOp = 1;
1602+
}
1603+
15871604
multiclass XVPseudoBinary<VReg RetClass,
15881605
VReg Op1Class,
15891606
DAGOperand Op2Class,
@@ -1612,6 +1629,20 @@ multiclass XVPseudoTiedBinary<VReg RetClass,
16121629
}
16131630
}
16141631

1632+
multiclass XVPseudoTernaryNoPolicy<VReg RetClass,
1633+
RegisterClass Op1Class,
1634+
DAGOperand Op2Class,
1635+
LMULInfo MInfo,
1636+
string Constraint = "",
1637+
bit Commutable = 0> {
1638+
let VLMul = MInfo.value in {
1639+
let isCommutable = Commutable in
1640+
def "_" # MInfo.MX : VPseudoTernaryNoMask<RetClass, Op1Class, Op2Class, Constraint>;
1641+
def "_" # MInfo.MX # "_MASK" : XVPseudoBinaryMaskNoPolicy<RetClass, Op1Class, Op2Class, Constraint>,
1642+
RISCVMaskedPseudo<MaskIdx=3>;
1643+
}
1644+
}
1645+
16151646
multiclass XVPseudoBinaryV_VV<LMULInfo m, string Constraint = "", int sew = 0> {
16161647
defm _VV : XVPseudoBinary<m.vrclass, m.vrclass, m.vrclass, m, Constraint, sew>;
16171648
}
@@ -1667,6 +1698,16 @@ multiclass XVPseudoBinaryVNSHT_VI<LMULInfo m> {
16671698
!if(!ge(m.octuple, 8), "@earlyclobber $rd", "")>;
16681699
}
16691700

1701+
multiclass XVPseudoTernaryV_VV_AAXA<LMULInfo m, string Constraint = ""> {
1702+
defm _VV : XVPseudoTernaryNoPolicy<m.vrclass, m.vrclass, m.vrclass, m,
1703+
Constraint, Commutable=1>;
1704+
}
1705+
1706+
multiclass XVPseudoTernaryV_VX_AAXA<LMULInfo m, string Constraint = ""> {
1707+
defm _VX : XVPseudoTernaryNoPolicy<m.vrclass, GPR, m.vrclass, m,
1708+
Constraint, Commutable=1>;
1709+
}
1710+
16701711
multiclass XVPseudoVALU_VV_VX_VI<Operand ImmType = simm5, string Constraint = ""> {
16711712
foreach m = MxListXTHeadV in {
16721713
defvar mx = m.MX;
@@ -1961,6 +2002,23 @@ multiclass XVPseudoVWMUL_VV_VX {
19612002
}
19622003
}
19632004

2005+
multiclass XVPseudoVMAC_VV_VX_AAXA<string Constraint = ""> {
2006+
foreach m = MxListXTHeadV in {
2007+
defvar mx = m.MX;
2008+
defvar WriteVIMulAddV_MX = !cast<SchedWrite>("WriteVIMulAddV_" # mx);
2009+
defvar WriteVIMulAddX_MX = !cast<SchedWrite>("WriteVIMulAddX_" # mx);
2010+
defvar ReadVIMulAddV_MX = !cast<SchedRead>("ReadVIMulAddV_" # mx);
2011+
defvar ReadVIMulAddX_MX = !cast<SchedRead>("ReadVIMulAddX_" # mx);
2012+
2013+
defm "" : XVPseudoTernaryV_VV_AAXA<m, Constraint>,
2014+
Sched<[WriteVIMulAddV_MX, ReadVIMulAddV_MX, ReadVIMulAddV_MX,
2015+
ReadVIMulAddV_MX, ReadVMask]>;
2016+
defm "" : XVPseudoTernaryV_VX_AAXA<m, Constraint>,
2017+
Sched<[WriteVIMulAddX_MX, ReadVIMulAddV_MX, ReadVIMulAddV_MX,
2018+
ReadVIMulAddX_MX, ReadVMask]>;
2019+
}
2020+
}
2021+
19642022
//===----------------------------------------------------------------------===//
19652023
// Helpers to define the intrinsic patterns for the XTHeadVector extension.
19662024
//===----------------------------------------------------------------------===//
@@ -2331,6 +2389,27 @@ multiclass XVPseudoVMINMAX_VV_VX {
23312389
}
23322390
}
23332391

2392+
multiclass XVPatTernaryV_VV_AAXA<string intrinsic, string instruction,
2393+
list<VTypeInfo> vtilist> {
2394+
foreach vti = vtilist in
2395+
let Predicates = GetXVTypePredicates<vti>.Predicates in
2396+
defm : VPatTernary<intrinsic, instruction, "VV",
2397+
vti.Vector, vti.Vector, vti.Vector, vti.Mask,
2398+
vti.Log2SEW, vti.LMul, vti.RegClass,
2399+
vti.RegClass, vti.RegClass>;
2400+
}
2401+
2402+
multiclass XVPatTernaryV_VX_AAXA<string intrinsic, string instruction,
2403+
list<VTypeInfo> vtilist> {
2404+
foreach vti = vtilist in
2405+
let Predicates = GetXVTypePredicates<vti>.Predicates in
2406+
defm : VPatTernary<intrinsic, instruction,
2407+
"V"#vti.ScalarSuffix,
2408+
vti.Vector, vti.Scalar, vti.Vector, vti.Mask,
2409+
vti.Log2SEW, vti.LMul, vti.RegClass,
2410+
vti.ScalarRegClass, vti.RegClass>;
2411+
}
2412+
23342413
multiclass XVPatBinaryV_VV_VX_VI<string intrinsic, string instruction,
23352414
list<VTypeInfo> vtilist, Operand ImmType = simm5>
23362415
: XVPatBinaryV_VV<intrinsic, instruction, vtilist>,
@@ -2397,6 +2476,11 @@ multiclass XVPatBinaryM_VX_VI<string intrinsic, string instruction,
23972476
: XVPatBinaryM_VX<intrinsic, instruction, vtilist>,
23982477
XVPatBinaryM_VI<intrinsic, instruction, vtilist>;
23992478

2479+
multiclass XVPatTernaryV_VV_VX_AAXA<string intrinsic, string instruction,
2480+
list<VTypeInfo> vtilist>
2481+
: XVPatTernaryV_VV_AAXA<intrinsic, instruction, vtilist>,
2482+
XVPatTernaryV_VX_AAXA<intrinsic, instruction, vtilist>;
2483+
24002484
//===----------------------------------------------------------------------===//
24012485
// 12.1. Vector Single-Width Saturating Add and Subtract
24022486
//===----------------------------------------------------------------------===//
@@ -2674,6 +2758,23 @@ let Predicates = [HasVendorXTHeadV] in {
26742758
defm : XVPatBinaryW_VV_VX<"int_riscv_th_vwmulsu", "PseudoTH_VWMULSU", AllWidenableIntXVectors>;
26752759
} // Predicates = [HasVendorXTHeadV]
26762760

2761+
//===----------------------------------------------------------------------===//
2762+
// 12.12. Vector Single-Width Integer Multiply-Add Instructions
2763+
//===----------------------------------------------------------------------===//
2764+
let Predicates = [HasVendorXTHeadV] in {
2765+
defm PseudoTH_VMACC : XVPseudoVMAC_VV_VX_AAXA;
2766+
defm PseudoTH_VNMSAC : XVPseudoVMAC_VV_VX_AAXA;
2767+
defm PseudoTH_VMADD : XVPseudoVMAC_VV_VX_AAXA;
2768+
defm PseudoTH_VNMSUB : XVPseudoVMAC_VV_VX_AAXA;
2769+
} // Predicates = [HasVendorXTHeadV]
2770+
2771+
let Predicates = [HasVendorXTHeadV] in {
2772+
defm : XVPatTernaryV_VV_VX_AAXA<"int_riscv_th_vmadd", "PseudoTH_VMADD", AllIntegerXVectors>;
2773+
defm : XVPatTernaryV_VV_VX_AAXA<"int_riscv_th_vnmsub", "PseudoTH_VNMSUB", AllIntegerXVectors>;
2774+
defm : XVPatTernaryV_VV_VX_AAXA<"int_riscv_th_vmacc", "PseudoTH_VMACC", AllIntegerXVectors>;
2775+
defm : XVPatTernaryV_VV_VX_AAXA<"int_riscv_th_vnmsac", "PseudoTH_VNMSAC", AllIntegerXVectors>;
2776+
} // Predicates = [HasVendorXTHeadV]
2777+
26772778
//===----------------------------------------------------------------------===//
26782779
// 12.14. Vector Integer Merge and Move Instructions
26792780
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)