Skip to content

Commit

Permalink
[RISCV] Add SDNode patterns for vandn.[vv,vx]
Browse files Browse the repository at this point in the history
Unfortunately we can't use the standard splat_vector and vnot PatFrags because
they are preprocessed to vmv.v.x's, so we need to define helpers to catch
those. We can't use SplatPat either because we need to nest another fragment
inside of it.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D155433
  • Loading branch information
lukel97 committed Jul 18, 2023
1 parent db39328 commit 26ff4c6
Show file tree
Hide file tree
Showing 2 changed files with 2,036 additions and 0 deletions.
30 changes: 30 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ let Predicates = [HasStdExtZvksh], RVVConstraint = NoConstraint in {
// Pseudo instructions
//===----------------------------------------------------------------------===//

defm PseudoVANDN : VPseudoVALU_VV_VX;

multiclass VPseudoUnaryV_V {
foreach m = MxList in {
let VLMul = m.value in {
Expand Down Expand Up @@ -215,6 +217,34 @@ multiclass VPatUnarySDNode_V<SDPatternOperator op, string instruction_name> {
}
}

// Helpers for detecting splats since we preprocess splat_vector to vmv.v.x
// This should match the logic in RISCVDAGToDAGISel::selectVSplat
def riscv_splat_vector : PatFrag<(ops node:$rs1),
(riscv_vmv_v_x_vl undef, node:$rs1, srcvalue)>;
def riscv_vnot : PatFrag<(ops node:$rs1), (xor node:$rs1,
(riscv_splat_vector -1))>;

foreach vti = AllIntegerVectors in {
let Predicates = !listconcat([HasStdExtZvbb],
GetVTypePredicates<vti>.Predicates) in {
def : Pat<(vti.Vector (and (riscv_vnot vti.RegClass:$rs1),
vti.RegClass:$rs2)),
(!cast<Instruction>("PseudoVANDN_VV_"#vti.LMul.MX)
(vti.Vector (IMPLICIT_DEF)),
vti.RegClass:$rs2,
vti.RegClass:$rs1,
vti.AVL, vti.Log2SEW, TA_MA)>;
def : Pat<(vti.Vector (and (riscv_splat_vector
(not vti.ScalarRegClass:$rs1)),
vti.RegClass:$rs2)),
(!cast<Instruction>("PseudoVANDN_VX_"#vti.LMul.MX)
(vti.Vector (IMPLICIT_DEF)),
vti.RegClass:$rs2,
vti.ScalarRegClass:$rs1,
vti.AVL, vti.Log2SEW, TA_MA)>;
}
}

defm : VPatUnarySDNode_V<bitreverse, "PseudoVBREV">;
defm : VPatUnarySDNode_V<bswap, "PseudoVREV8">;
defm : VPatUnarySDNode_V<ctlz, "PseudoVCLZ">;
Expand Down

0 comments on commit 26ff4c6

Please sign in to comment.