Skip to content

Commit

Permalink
[Clang][RISCV] Update operand order for vmerge and vcompress
Browse files Browse the repository at this point in the history
From:
  vint32m1_t vmerge_vvm_i32m1 (vbool32_t mask, vint32m1_t op1, vint32m1_t op2, size_t vl);
  vint32m1_t vcompress_vm_i32m1 (vbool32_t mask, vint32m1_t src, size_t vl);

To:
  vint32m1_t vmerge_vvm_i32m1 (vint32m1_t op1, vint32m1_t op2, vbool32_t selector, size_t vl);
  vint32m1_t vcompress_vm_i32m1 (vint32m1_t src, vbool32_t selector, size_t vl);

Address issues:
riscv-non-isa/rvv-intrinsic-doc#140
riscv-non-isa/rvv-intrinsic-doc#167

Pull request:
riscv-non-isa/rvv-intrinsic-doc#185

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D140686
  • Loading branch information
eopXD authored and CarlosAlbertoEnciso committed Jan 13, 2023
1 parent 993df8b commit 7936aaa
Show file tree
Hide file tree
Showing 15 changed files with 2,135 additions and 2,152 deletions.
27 changes: 11 additions & 16 deletions clang/include/clang/Basic/riscv_vector.td
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ class PolicyScheme<int val>{
def NonePolicy : PolicyScheme<0>;
def HasPassthruOperand : PolicyScheme<1>;
def HasPolicyOperand : PolicyScheme<2>;
// Specail case for passthru operand which is not a first opeand.
def HasPassthruOperandAtIdx1 : PolicyScheme<3>;

class RVVBuiltin<string suffix, string prototype, string type_range,
string overloaded_suffix = ""> {
Expand Down Expand Up @@ -1878,20 +1876,19 @@ defm vwmaccus : RVVOutOp1Op2BuiltinSet<"vwmaccus", "csi",
// 12.15. Vector Integer Merge Instructions
// C/C++ Operand: (mask, op1, op2, vl), Intrinsic: (passthru, op1, op2, mask, vl)
let HasMasked = false,
UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
UnMaskedPolicyScheme = HasPassthruOperand,
MaskedPolicyScheme = NonePolicy,
ManualCodegen = [{
std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
// insert poison passthru
if (PolicyAttrs == TAIL_AGNOSTIC)
Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
IntrinsicTypes = {ResultType, Ops[2]->getType(), Ops.back()->getType()};
}] in {
defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "csil",
[["vvm", "v", "vmvv"],
["vxm", "v", "vmve"],
["vvm", "Uv", "UvmUvUv"],
["vxm", "Uv", "UvmUvUe"]]>;
[["vvm", "v", "vvvm"],
["vxm", "v", "vvem"],
["vvm", "Uv", "UvUvUvm"],
["vxm", "Uv", "UvUvUem"]]>;
}

// 12.16. Vector Integer Move Instructions
Expand Down Expand Up @@ -2022,19 +2019,18 @@ let Name = "vfclass_v", UnMaskedPolicyScheme = HasPassthruOperand in
// 14.15. Vector Floating-Point Merge Instructio
// C/C++ Operand: (mask, op1, op2, vl), Builtin: (op1, op2, mask, vl)
let HasMasked = false,
UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
UnMaskedPolicyScheme = HasPassthruOperand,
MaskedPolicyScheme = NonePolicy,
ManualCodegen = [{
std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
// insert poison passthru
if (PolicyAttrs == TAIL_AGNOSTIC)
Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
IntrinsicTypes = {ResultType, Ops[2]->getType(), Ops.back()->getType()};
}] in {
defm vmerge : RVVOutOp1BuiltinSet<"vmerge", "xfd",
[["vvm", "v", "vmvv"]]>;
[["vvm", "v", "vvvm"]]>;
defm vfmerge : RVVOutOp1BuiltinSet<"vfmerge", "xfd",
[["vfm", "v", "vmve"]]>;
[["vfm", "v", "vvem"]]>;
}

// 14.16. Vector Floating-Point Move Instruction
Expand Down Expand Up @@ -2222,21 +2218,20 @@ defm vrgatherei16 : RVVOutBuiltinSet<"vrgatherei16_vv", "csil",
// 17.5. Vector Compress Instruction
let IsPrototypeDefaultTU = true,
HasMasked = false,
UnMaskedPolicyScheme = HasPassthruOperandAtIdx1,
UnMaskedPolicyScheme = HasPassthruOperand,
MaskedPolicyScheme = NonePolicy,
ManualCodegen = [{
std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
// insert poison passthru
if (PolicyAttrs == TAIL_AGNOSTIC)
Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
IntrinsicTypes = {ResultType, Ops.back()->getType()};
}] in {
// signed and floating type
defm vcompress : RVVOutBuiltinSet<"vcompress", "csilxfd",
[["vm", "v", "vmvv"]]>;
[["vm", "v", "vvvm"]]>;
// unsigned type
defm vcompress : RVVOutBuiltinSet<"vcompress", "csil",
[["vm", "Uv", "UvmUvUv"]]>;
[["vm", "Uv", "UvUvUvm"]]>;
}

// Miscellaneous
Expand Down
3 changes: 0 additions & 3 deletions clang/include/clang/Support/RISCVVIntrinsicUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,6 @@ enum PolicyScheme : uint8_t {
// Passthru operand is at first parameter in C builtin.
HasPassthruOperand,
HasPolicyOperand,
// Special case for vmerge, the passthru operand is second
// parameter in C builtin.
HasPassthruOperandAtIdx1,
};

// TODO refactor RVVIntrinsic class design after support all intrinsic
Expand Down
9 changes: 0 additions & 9 deletions clang/lib/Support/RISCVVIntrinsicUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,15 +964,6 @@ llvm::SmallVector<PrototypeDescriptor> RVVIntrinsic::computeBuiltinTypes(
else if (PolicyAttrs.isTAPolicy() && HasPassthruOp &&
IsPrototypeDefaultTU)
NewPrototype.erase(NewPrototype.begin() + 1);
if (DefaultScheme == PolicyScheme::HasPassthruOperandAtIdx1) {
if (PolicyAttrs.isTUPolicy() && !IsPrototypeDefaultTU) {
// Insert undisturbed output to index 1
NewPrototype.insert(NewPrototype.begin() + 2, NewPrototype[0]);
} else if (PolicyAttrs.isTAPolicy() && IsPrototypeDefaultTU) {
// Erase passthru for TA policy
NewPrototype.erase(NewPrototype.begin() + 2);
}
}
} else if (PolicyAttrs.isTUPolicy() && HasPassthruOp) {
// NF > 1 cases for segment load operations.
// Convert
Expand Down
Loading

0 comments on commit 7936aaa

Please sign in to comment.