Skip to content

Commit

Permalink
[RISCV] Make SplatOperand start from 0.
Browse files Browse the repository at this point in the history
Current SplatOperand starts from 1 because operand 0 (or 1) is intrinsic
id in SelectionDAG.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D117453
  • Loading branch information
HanKuanChen authored and topperc committed Jan 18, 2022
1 parent c29d6c4 commit 3fc4b58
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
38 changes: 20 additions & 18 deletions llvm/include/llvm/IR/IntrinsicsRISCV.td
Expand Up @@ -120,12 +120,14 @@ let TargetPrefix = "riscv" in {
//===----------------------------------------------------------------------===//
// Vectors

// The intrinsic does not have any operand that must be extended.
defvar NoSplatOperand = 0xF;

class RISCVVIntrinsic {
// These intrinsics may accept illegal integer values in their llvm_any_ty
// operand, so they have to be extended. If set to zero then the intrinsic
// does not have any operand that must be extended.
// operand, so they have to be extended.
Intrinsic IntrinsicID = !cast<Intrinsic>(NAME);
bits<4> SplatOperand = 0;
bits<4> SplatOperand = NoSplatOperand;
}

let TargetPrefix = "riscv" in {
Expand Down Expand Up @@ -344,7 +346,7 @@ let TargetPrefix = "riscv" in {
: Intrinsic<[llvm_anyvector_ty],
[LLVMMatchType<0>, llvm_any_ty, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For destination vector type is the same as first source vector (with mask).
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl, ta)
Expand All @@ -354,7 +356,7 @@ let TargetPrefix = "riscv" in {
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty,
LLVMMatchType<2>],
[ImmArg<ArgIndex<5>>, IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 3;
let SplatOperand = 2;
}
// For destination vector type is the same as first source vector. The
// second source operand must match the destination type or be an XLen scalar.
Expand All @@ -378,7 +380,7 @@ let TargetPrefix = "riscv" in {
: Intrinsic<[llvm_anyvector_ty],
[llvm_anyvector_ty, llvm_any_ty, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For destination vector type is NOT the same as first source vector (with mask).
// Input: (maskedoff, vector_in, vector_in/scalar_in, mask, vl, ta)
Expand All @@ -388,7 +390,7 @@ let TargetPrefix = "riscv" in {
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty,
LLVMMatchType<3>],
[ImmArg<ArgIndex<5>>, IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 3;
let SplatOperand = 2;
}
// For destination vector type is NOT the same as first source vector. The
// second source operand must match the destination type or be an XLen scalar.
Expand All @@ -414,7 +416,7 @@ let TargetPrefix = "riscv" in {
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For binary operations with mask type output and V0 as input.
// Output: (mask type output)
Expand All @@ -425,7 +427,7 @@ let TargetPrefix = "riscv" in {
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>,
llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For binary operations with mask type output.
// Output: (mask type output)
Expand All @@ -434,7 +436,7 @@ let TargetPrefix = "riscv" in {
: Intrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
[llvm_anyvector_ty, llvm_any_ty, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For binary operations with mask type output without mask.
// Output: (mask type output)
Expand All @@ -443,7 +445,7 @@ let TargetPrefix = "riscv" in {
: Intrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>],
[llvm_anyvector_ty, llvm_any_ty, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For binary operations with mask type output with mask.
// Output: (mask type output)
Expand All @@ -454,7 +456,7 @@ let TargetPrefix = "riscv" in {
llvm_anyvector_ty, llvm_any_ty,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 3;
let SplatOperand = 2;
}
// For FP classify operations.
// Output: (bit mask type output)
Expand All @@ -478,7 +480,7 @@ let TargetPrefix = "riscv" in {
: Intrinsic<[llvm_anyvector_ty],
[LLVMMatchType<0>, llvm_any_ty, llvm_anyint_ty],
[IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For Saturating binary operations with mask.
// The destination vector type is the same as first source vector.
Expand All @@ -489,7 +491,7 @@ let TargetPrefix = "riscv" in {
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty,
LLVMMatchType<2>],
[ImmArg<ArgIndex<5>>, IntrNoMem, IntrHasSideEffects]>, RISCVVIntrinsic {
let SplatOperand = 3;
let SplatOperand = 2;
}
// For Saturating binary operations.
// The destination vector type is the same as first source vector.
Expand Down Expand Up @@ -542,28 +544,28 @@ let TargetPrefix = "riscv" in {
[LLVMMatchType<0>, llvm_any_ty, LLVMMatchType<0>,
llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
class RISCVTernaryAAXAMask
: Intrinsic<[llvm_anyvector_ty],
[LLVMMatchType<0>, llvm_any_ty, LLVMMatchType<0>,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
class RISCVTernaryWideNoMask
: Intrinsic< [llvm_anyvector_ty],
[LLVMMatchType<0>, llvm_any_ty, llvm_anyvector_ty,
llvm_anyint_ty],
[IntrNoMem] >, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
class RISCVTernaryWideMask
: Intrinsic< [llvm_anyvector_ty],
[LLVMMatchType<0>, llvm_any_ty, llvm_anyvector_ty,
LLVMScalarOrSameVectorWidth<0, llvm_i1_ty>, llvm_anyint_ty],
[IntrNoMem]>, RISCVVIntrinsic {
let SplatOperand = 2;
let SplatOperand = 1;
}
// For Reduction ternary operations.
// For destination vector type is the same as first and third source vector.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Expand Up @@ -4151,10 +4151,10 @@ static SDValue lowerVectorIntrinsicSplats(SDValue Op, SelectionDAG &DAG,

const RISCVVIntrinsicsTable::RISCVVIntrinsicInfo *II =
RISCVVIntrinsicsTable::getRISCVVIntrinsicInfo(IntNo);
if (!II || !II->SplatOperand)
if (!II || !II->hasSplatOperand())
return SDValue();

unsigned SplatOp = II->SplatOperand + HasChain;
unsigned SplatOp = II->SplatOperand + 1 + HasChain;
assert(SplatOp < Op.getNumOperands());

SmallVector<SDValue, 8> Operands(Op->op_begin(), Op->op_end());
Expand Down Expand Up @@ -4184,7 +4184,7 @@ static SDValue lowerVectorIntrinsicSplats(SDValue Op, SelectionDAG &DAG,
// that a widening operation never uses SEW=64.
// NOTE: If this fails the below assert, we can probably just find the
// element count from any operand or result and use it to construct the VT.
assert(II->SplatOperand > 1 && "Unexpected splat operand!");
assert(II->SplatOperand > 0 && "Unexpected splat operand!");
MVT VT = Op.getOperand(SplatOp - 1).getSimpleValueType();

// The more complex case is when the scalar is larger than XLenVT.
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelLowering.h
Expand Up @@ -670,6 +670,10 @@ namespace RISCVVIntrinsicsTable {
struct RISCVVIntrinsicInfo {
unsigned IntrinsicID;
uint8_t SplatOperand;
bool hasSplatOperand() const {
// 0xF is not valid. See NoSplatOperand in IntrinsicsRISCV.td.
return SplatOperand != 0xF;
}
};

using namespace RISCV;
Expand Down

0 comments on commit 3fc4b58

Please sign in to comment.