Skip to content

Commit 8ecfe9a

Browse files
[RISCV][GISEL][NFC] Add typeIsLegalBoolVec and typeIsLegalIntOrFPVec helpers
1 parent 9405d5a commit 8ecfe9a

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ static LegalityPredicate typeIsScalarFPArith(unsigned TypeIdx,
4040
};
4141
}
4242

43+
static LegalityPredicate
44+
typeIsLegalIntOrFPVec(unsigned TypeIdx,
45+
std::initializer_list<LLT> IntOrFPVecTys,
46+
const RISCVSubtarget &ST) {
47+
return [=, &ST](const LegalityQuery &Query) {
48+
return typeInSet(TypeIdx, IntOrFPVecTys) && ST.hasVInstructions() &&
49+
(Query.Types[TypeIdx].getScalarSizeInBits() != 64 ||
50+
ST.hasVInstructionsI64()) &&
51+
(Query.Types[TypeIdx].getElementCount().getKnownMinValue() != 1 ||
52+
ST.getELen() == 64);
53+
};
54+
}
55+
56+
static LegalityPredicate
57+
typeIsLegalBoolVec(unsigned TypeIdx, std::initializer_list<LLT> BoolVecTys,
58+
const RISCVSubtarget &ST) {
59+
return [=, &ST](const LegalityQuery &Query) {
60+
return typeInSet(TypeIdx, BoolVecTys) && ST.hasVInstructions();
61+
};
62+
}
63+
4364
RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
4465
: STI(ST), XLen(STI.getXLen()), sXLen(LLT::scalar(XLen)) {
4566
const LLT sDoubleXLen = LLT::scalar(2 * XLen);
@@ -50,6 +71,14 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
5071
const LLT s32 = LLT::scalar(32);
5172
const LLT s64 = LLT::scalar(64);
5273

74+
const LLT nxv1s1 = LLT::scalable_vector(1, s1);
75+
const LLT nxv2s1 = LLT::scalable_vector(2, s1);
76+
const LLT nxv4s1 = LLT::scalable_vector(4, s1);
77+
const LLT nxv8s1 = LLT::scalable_vector(8, s1);
78+
const LLT nxv16s1 = LLT::scalable_vector(16, s1);
79+
const LLT nxv32s1 = LLT::scalable_vector(32, s1);
80+
const LLT nxv64s1 = LLT::scalable_vector(64, s1);
81+
5382
const LLT nxv1s8 = LLT::scalable_vector(1, s8);
5483
const LLT nxv2s8 = LLT::scalable_vector(2, s8);
5584
const LLT nxv4s8 = LLT::scalable_vector(4, s8);
@@ -78,22 +107,17 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
78107

79108
using namespace TargetOpcode;
80109

81-
auto AllVecTys = {nxv1s8, nxv2s8, nxv4s8, nxv8s8, nxv16s8, nxv32s8,
82-
nxv64s8, nxv1s16, nxv2s16, nxv4s16, nxv8s16, nxv16s16,
83-
nxv32s16, nxv1s32, nxv2s32, nxv4s32, nxv8s32, nxv16s32,
84-
nxv1s64, nxv2s64, nxv4s64, nxv8s64};
110+
111+
auto BoolVecTys = {nxv1s1, nxv2s1, nxv4s1, nxv8s1, nxv16s1, nxv32s1, nxv64s1};
112+
113+
auto IntOrFPVecTys = {nxv1s8, nxv2s8, nxv4s8, nxv8s8, nxv16s8, nxv32s8,
114+
nxv64s8, nxv1s16, nxv2s16, nxv4s16, nxv8s16, nxv16s16,
115+
nxv32s16, nxv1s32, nxv2s32, nxv4s32, nxv8s32, nxv16s32,
116+
nxv1s64, nxv2s64, nxv4s64, nxv8s64};
85117

86118
getActionDefinitionsBuilder({G_ADD, G_SUB, G_AND, G_OR, G_XOR})
87119
.legalFor({s32, sXLen})
88-
.legalIf(all(
89-
typeInSet(0, AllVecTys),
90-
LegalityPredicate([=, &ST](const LegalityQuery &Query) {
91-
return ST.hasVInstructions() &&
92-
(Query.Types[0].getScalarSizeInBits() != 64 ||
93-
ST.hasVInstructionsI64()) &&
94-
(Query.Types[0].getElementCount().getKnownMinValue() != 1 ||
95-
ST.getELen() == 64);
96-
})))
120+
.legalIf(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST))
97121
.widenScalarToNextPow2(0)
98122
.clampScalar(0, s32, sXLen);
99123

0 commit comments

Comments
 (0)