-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RISCV] Add codegen support for ri.vinsert.v.x and ri.vextract.x.v #136708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
84ff8d8
e29f829
7122db2
9c0b760
c37b00f
92e2acb
874a86a
e98da02
011538e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,10 @@ static bool isFloatScalarMoveOrScalarSplatInstr(const MachineInstr &MI) { | |
| } | ||
| } | ||
|
|
||
| static bool isVExtractInstr(const MachineInstr &MI) { | ||
| return RISCV::getRVVMCOpcode(MI.getOpcode()) == RISCV::RI_VEXTRACT; | ||
| } | ||
|
|
||
| static bool isScalarExtractInstr(const MachineInstr &MI) { | ||
| switch (RISCV::getRVVMCOpcode(MI.getOpcode())) { | ||
| default: | ||
|
|
@@ -538,6 +542,12 @@ DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST) { | |
| Res.MaskPolicy = false; | ||
| } | ||
|
|
||
| if (isVExtractInstr(MI)) { | ||
| assert(!RISCVII::hasVLOp(TSFlags)); | ||
| // TODO: LMUL can be any larger value (without cost) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be an interesting optimisation. I could imagine us having more demanded LMUL types e.g.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a sense, we sort of already have this for vmv.s.x and vmv.x.s, it's just that the MX value is the smallest legal LMUL, and thus GTE becomes any LMUL. |
||
| Res.TailPolicy = false; | ||
| } | ||
|
|
||
| return Res; | ||
| } | ||
|
|
||
|
|
@@ -1085,7 +1095,7 @@ RISCVInsertVSETVLI::computeInfoForInstr(const MachineInstr &MI) const { | |
| InstrInfo.setAVLRegDef(VNI, VLOp.getReg()); | ||
| } | ||
| } else { | ||
| assert(isScalarExtractInstr(MI)); | ||
| assert(isScalarExtractInstr(MI) || isVExtractInstr(MI)); | ||
| // Pick a random value for state tracking purposes, will be ignored via | ||
| // the demanded fields mechanism | ||
| InstrInfo.setAVLImm(1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,3 +128,57 @@ def RI_VEXTRACT : CustomRivosXVI<0b010111, OPMVV, (outs GPR:$rd), | |
| (ins VR:$vs2, uimm5:$imm), | ||
| "ri.vextract.x.v", "$rd, $vs2, $imm">; | ||
| } | ||
|
|
||
|
|
||
| def ri_vextract : SDNode<"RISCVISD::RI_VEXTRACT", | ||
| SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisVec<1>, | ||
| SDTCisInt<2>, | ||
| SDTCisInt<1>]>>; | ||
|
|
||
| def ri_vinsert_vl : SDNode<"RISCVISD::RI_VINSERT_VL", | ||
| SDTypeProfile<1, 5, [SDTCisSameAs<0, 1>, | ||
| SDTCisInt<0>, | ||
| SDTCisVT<2, XLenVT>, | ||
| SDTCisVT<3, XLenVT>, | ||
| SDTCisVT<4, XLenVT>]>>; | ||
|
|
||
| let Predicates = [HasVendorXRivosVisni], mayLoad = 0, mayStore = 0, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not thrilled with this bit of tablegen, if anyone has suggestions on how to improve, please let me know!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks fine to me, is there anything in particular that you're worried about? |
||
| hasSideEffects = 0, HasSEWOp = 1 in | ||
| foreach m = MxList in { | ||
| defvar mx = m.MX; | ||
| let VLMul = m.value in { | ||
| let BaseInstr = RI_VEXTRACT in | ||
| def PseudoRI_VEXTRACT_ # mx : | ||
| Pseudo<(outs GPR:$rd), (ins m.vrclass:$rs2, uimm5:$idx, ixlenimm:$sew), | ||
| []>, | ||
| RISCVVPseudo; | ||
|
|
||
| let HasVLOp = 1, BaseInstr = RI_VINSERT, HasVecPolicyOp = 1, | ||
| Constraints = "$rd = $rs1" in | ||
| def PseudoRI_VINSERT_ # mx : | ||
| Pseudo<(outs m.vrclass:$rd), | ||
| (ins m.vrclass:$rs1, GPR:$rs2, uimm5:$idx, AVL:$vl, | ||
| ixlenimm:$sew, ixlenimm:$policy), | ||
| []>, | ||
| RISCVVPseudo; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| foreach vti = AllIntegerVectors in | ||
| let Predicates = GetVTypePredicates<vti>.Predicates in { | ||
| def : Pat<(XLenVT (ri_vextract (vti.Vector vti.RegClass:$vs2), uimm5:$imm)), | ||
| (!cast<Instruction>("PseudoRI_VEXTRACT_" # vti.LMul.MX) | ||
| $vs2, uimm5:$imm, vti.Log2SEW)>; | ||
|
|
||
| def : Pat<(vti.Vector (ri_vinsert_vl (vti.Vector vti.RegClass:$merge), | ||
| vti.ScalarRegClass:$rs1, | ||
| uimm5:$imm, | ||
| VLOpFrag, | ||
| (XLenVT timm:$policy))), | ||
| (!cast<Instruction>("PseudoRI_VINSERT_" # vti.LMul.MX) | ||
| $merge, vti.ScalarRegClass:$rs1, uimm5:$imm, | ||
| GPR:$vl, vti.Log2SEW, (XLenVT timm:$policy))>; | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware that this is copied from the existing case below, but if the VL here is always going to be >= VLMAX then can we not always set RISCVVType::TAIL_AGNOSTIC?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VL is always going to be <= VLMAX, not the other way around. But yes, you're correct that we can set TA in all cases here. I'll do that before landing.
Edit: For clarity, this depends on a specification clarification of what elements are tail elements for this instruction which hasn't yet been pushed. In short, it's the elements past VLMAX (since we allow writes past VL), but the usual past VL. This means that only fractional LMUL have tail elements.