Skip to content

Commit 33cf27b

Browse files
[RISCV][GISEL][NFC] Add typeIsLegalBoolVec and typeIsLegalIntOrFPVec helpers
1 parent c62c746 commit 33cf27b

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

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

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,30 @@ 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+
LegalityPredicate P = [=, &ST](const LegalityQuery &Query) {
48+
return 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+
return all(typeInSet(TypeIdx, IntOrFPVecTys), P);
56+
}
57+
58+
static LegalityPredicate
59+
typeIsLegalBoolVec(unsigned TypeIdx, std::initializer_list<LLT> BoolVecTys,
60+
const RISCVSubtarget &ST) {
61+
LegalityPredicate HasV = [=, &ST](const LegalityQuery &Query) {
62+
return ST.hasVInstructions();
63+
};
64+
return all(typeInSet(TypeIdx, BoolVecTys), HasV);
65+
}
66+
4367
RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
4468
: STI(ST), XLen(STI.getXLen()), sXLen(LLT::scalar(XLen)) {
4569
const LLT sDoubleXLen = LLT::scalar(2 * XLen);
@@ -50,6 +74,14 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
5074
const LLT s32 = LLT::scalar(32);
5175
const LLT s64 = LLT::scalar(64);
5276

77+
const LLT nxv1s1 = LLT::scalable_vector(1, s1);
78+
const LLT nxv2s1 = LLT::scalable_vector(2, s1);
79+
const LLT nxv4s1 = LLT::scalable_vector(4, s1);
80+
const LLT nxv8s1 = LLT::scalable_vector(8, s1);
81+
const LLT nxv16s1 = LLT::scalable_vector(16, s1);
82+
const LLT nxv32s1 = LLT::scalable_vector(32, s1);
83+
const LLT nxv64s1 = LLT::scalable_vector(64, s1);
84+
5385
const LLT nxv1s8 = LLT::scalable_vector(1, s8);
5486
const LLT nxv2s8 = LLT::scalable_vector(2, s8);
5587
const LLT nxv4s8 = LLT::scalable_vector(4, s8);
@@ -78,22 +110,16 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
78110

79111
using namespace TargetOpcode;
80112

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};
113+
auto BoolVecTys = {nxv1s1, nxv2s1, nxv4s1, nxv8s1, nxv16s1, nxv32s1, nxv64s1};
114+
115+
auto IntOrFPVecTys = {nxv1s8, nxv2s8, nxv4s8, nxv8s8, nxv16s8, nxv32s8,
116+
nxv64s8, nxv1s16, nxv2s16, nxv4s16, nxv8s16, nxv16s16,
117+
nxv32s16, nxv1s32, nxv2s32, nxv4s32, nxv8s32, nxv16s32,
118+
nxv1s64, nxv2s64, nxv4s64, nxv8s64};
85119

86120
getActionDefinitionsBuilder({G_ADD, G_SUB, G_AND, G_OR, G_XOR})
87121
.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-
})))
122+
.legalIf(typeIsLegalIntOrFPVec(0, IntOrFPVecTys, ST))
97123
.widenScalarToNextPow2(0)
98124
.clampScalar(0, s32, sXLen);
99125

0 commit comments

Comments
 (0)