Skip to content

Commit 50ca2e5

Browse files
committed
Take out most pattern match changes
1 parent 158f82a commit 50ca2e5

File tree

3 files changed

+30
-53
lines changed

3 files changed

+30
-53
lines changed

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
195195
/// Match a VPInstruction, capturing if we match.
196196
inline bind_ty<VPInstruction> m_VPInstruction(VPInstruction *&V) { return V; }
197197

198-
template <typename Ops_t, unsigned Opcode, bool Commutative, bool Variadic,
198+
template <typename Ops_t, unsigned Opcode, bool Commutative,
199199
typename... RecipeTys>
200200
struct Recipe_match {
201201
Ops_t Ops;
@@ -232,9 +232,9 @@ struct Recipe_match {
232232
return false;
233233

234234
if (R->getNumOperands() != std::tuple_size<Ops_t>::value) {
235-
assert(Variadic && "non-variadic recipe with matched opcode does not "
236-
"have the expected number of "
237-
"operands");
235+
assert(Opcode == Instruction::PHI &&
236+
"non-variadic recipe with matched opcode does not have the "
237+
"expected number of operands");
238238
return false;
239239
}
240240

@@ -259,9 +259,7 @@ struct Recipe_match {
259259
std::is_same<RecipeTy, VPCanonicalIVPHIRecipe>::value ||
260260
std::is_same<RecipeTy, VPWidenSelectRecipe>::value ||
261261
std::is_same<RecipeTy, VPDerivedIVRecipe>::value ||
262-
std::is_same<RecipeTy, VPWidenGEPRecipe>::value ||
263-
std::is_same<RecipeTy, VPWidenPHIRecipe>::value ||
264-
std::is_same<RecipeTy, VPHeaderPHIRecipe>::value)
262+
std::is_same<RecipeTy, VPWidenGEPRecipe>::value)
265263
return DefR;
266264
else
267265
return DefR && DefR->getOpcode() == Opcode;
@@ -277,11 +275,11 @@ struct Recipe_match {
277275

278276
template <unsigned Opcode, typename... RecipeTys>
279277
using ZeroOpRecipe_match =
280-
Recipe_match<std::tuple<>, Opcode, false, false, RecipeTys...>;
278+
Recipe_match<std::tuple<>, Opcode, false, RecipeTys...>;
281279

282280
template <typename Op0_t, unsigned Opcode, typename... RecipeTys>
283281
using UnaryRecipe_match =
284-
Recipe_match<std::tuple<Op0_t>, Opcode, false, false, RecipeTys...>;
282+
Recipe_match<std::tuple<Op0_t>, Opcode, false, RecipeTys...>;
285283

286284
template <typename Op0_t, unsigned Opcode>
287285
using UnaryVPInstruction_match =
@@ -298,8 +296,7 @@ using AllUnaryRecipe_match =
298296
template <typename Op0_t, typename Op1_t, unsigned Opcode, bool Commutative,
299297
typename... RecipeTys>
300298
using BinaryRecipe_match =
301-
Recipe_match<std::tuple<Op0_t, Op1_t>, Opcode, Commutative,
302-
/*Variadic*/ false, RecipeTys...>;
299+
Recipe_match<std::tuple<Op0_t, Op1_t>, Opcode, Commutative, RecipeTys...>;
303300

304301
template <typename Op0_t, typename Op1_t, unsigned Opcode>
305302
using BinaryVPInstruction_match =
@@ -308,9 +305,8 @@ using BinaryVPInstruction_match =
308305

309306
template <typename Op0_t, typename Op1_t, typename Op2_t, unsigned Opcode,
310307
bool Commutative, typename... RecipeTys>
311-
using TernaryRecipe_match =
312-
Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t>, Opcode, Commutative,
313-
/*Variadic*/ false, RecipeTys...>;
308+
using TernaryRecipe_match = Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t>,
309+
Opcode, Commutative, RecipeTys...>;
314310

315311
template <typename Op0_t, typename Op1_t, typename Op2_t, unsigned Opcode>
316312
using TernaryVPInstruction_match =
@@ -350,9 +346,8 @@ m_VPInstruction(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
350346

351347
template <typename Op0_t, typename Op1_t, typename Op2_t, typename Op3_t,
352348
unsigned Opcode, bool Commutative, typename... RecipeTys>
353-
using Recipe4Op_match =
354-
Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t, Op3_t>, Opcode, Commutative,
355-
/*Variadic*/ false, RecipeTys...>;
349+
using Recipe4Op_match = Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t, Op3_t>,
350+
Opcode, Commutative, RecipeTys...>;
356351

357352
template <typename Op0_t, typename Op1_t, typename Op2_t, typename Op3_t,
358353
unsigned Opcode>
@@ -386,12 +381,6 @@ m_Broadcast(const Op0_t &Op0) {
386381
return m_VPInstruction<VPInstruction::Broadcast>(Op0);
387382
}
388383

389-
template <typename Op0_t>
390-
inline UnaryVPInstruction_match<Op0_t, VPInstruction::ExplicitVectorLength>
391-
m_ExplicitVectorLength(const Op0_t &Op0) {
392-
return m_VPInstruction<VPInstruction::ExplicitVectorLength>(Op0);
393-
}
394-
395384
template <typename Op0_t, typename Op1_t>
396385
inline BinaryVPInstruction_match<Op0_t, Op1_t, VPInstruction::ActiveLaneMask>
397386
m_ActiveLaneMask(const Op0_t &Op0, const Op1_t &Op1) {
@@ -451,12 +440,6 @@ m_c_Binary(const Op0_t &Op0, const Op1_t &Op1) {
451440
return AllBinaryRecipe_match<Op0_t, Op1_t, Opcode, true>(Op0, Op1);
452441
}
453442

454-
template <typename Op0_t, typename Op1_t>
455-
inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::Sub>
456-
m_Sub(const Op0_t &Op0, const Op1_t &Op1) {
457-
return m_Binary<Instruction::Sub, Op0_t, Op1_t>(Op0, Op1);
458-
}
459-
460443
template <typename Op0_t, typename Op1_t>
461444
inline AllBinaryRecipe_match<Op0_t, Op1_t, Instruction::Mul>
462445
m_Mul(const Op0_t &Op0, const Op1_t &Op1) {
@@ -502,8 +485,7 @@ inline GEPLikeRecipe_match<Op0_t, Op1_t> m_GetElementPtr(const Op0_t &Op0,
502485
template <typename Op0_t, typename Op1_t, typename Op2_t, unsigned Opcode>
503486
using AllTernaryRecipe_match =
504487
Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t>, Opcode, false,
505-
/*Variadic*/ false, VPReplicateRecipe, VPInstruction,
506-
VPWidenSelectRecipe>;
488+
VPReplicateRecipe, VPInstruction, VPWidenSelectRecipe>;
507489

508490
template <typename Op0_t, typename Op1_t, typename Op2_t>
509491
inline AllTernaryRecipe_match<Op0_t, Op1_t, Op2_t, Instruction::Select>
@@ -551,26 +533,14 @@ m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
551533

552534
template <typename Op0_t, typename Op1_t, typename Op2_t>
553535
using VPDerivedIV_match =
554-
Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t>, 0, false, /*Variadic*/ false,
555-
VPDerivedIVRecipe>;
536+
Recipe_match<std::tuple<Op0_t, Op1_t, Op2_t>, 0, false, VPDerivedIVRecipe>;
556537

557538
template <typename Op0_t, typename Op1_t, typename Op2_t>
558539
inline VPDerivedIV_match<Op0_t, Op1_t, Op2_t>
559540
m_DerivedIV(const Op0_t &Op0, const Op1_t &Op1, const Op2_t &Op2) {
560541
return VPDerivedIV_match<Op0_t, Op1_t, Op2_t>({Op0, Op1, Op2});
561542
}
562543

563-
template <typename... OpTys>
564-
using PhiLikeRecipe_match =
565-
Recipe_match<std::tuple<OpTys...>, Instruction::PHI, false, true,
566-
VPWidenPHIRecipe, VPHeaderPHIRecipe, VPInstruction>;
567-
568-
template <typename Op0_t, typename Op1_t, typename... OpTys>
569-
inline PhiLikeRecipe_match<Op0_t, Op1_t, OpTys...>
570-
m_Phi(const Op0_t &Op0, const Op1_t &Op1, const OpTys &...Ops) {
571-
return PhiLikeRecipe_match<Op0_t, Op1_t, OpTys...>(Op0, Op1, Ops...);
572-
}
573-
574544
/// Match a call argument at a given argument index.
575545
template <typename Opnd_t> struct Argument_match {
576546
/// Call argument index to match.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
328328
// Pick out opcode, type/ext information and use sub side effects from a widen
329329
// recipe.
330330
auto HandleWiden = [&](VPWidenRecipe *Widen) {
331-
if (match(Widen, m_Sub(m_SpecificInt(0), m_VPValue(Op)))) {
331+
if (match(Widen,
332+
m_Binary<Instruction::Sub>(m_SpecificInt(0), m_VPValue(Op)))) {
332333
Widen = dyn_cast<VPWidenRecipe>(Op->getDefiningRecipe());
333334
}
334335
Opcode = Widen->getOpcode();

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ static VPWidenInductionRecipe *getOptimizableIVOf(VPValue *VPV) {
740740
// IVStep will be the negated step of the subtraction. Check if Step == -1
741741
// * IVStep.
742742
VPValue *Step;
743-
if (!match(VPV, m_Sub(m_VPValue(), m_VPValue(Step))) ||
743+
if (!match(VPV,
744+
m_Binary<Instruction::Sub>(m_VPValue(), m_VPValue(Step))) ||
744745
!Step->isLiveIn() || !IVStep->isLiveIn())
745746
return false;
746747
auto *StepCI = dyn_cast<ConstantInt>(Step->getLiveInIRValue());
@@ -2400,13 +2401,18 @@ void VPlanTransforms::canonicalizeEVLLoops(VPlan &Plan) {
24002401
continue;
24012402
}
24022403
if (match(PhiR,
2403-
m_Phi(m_Specific(Plan.getTripCount()), m_VPValue(Backedge))) &&
2404-
match(Backedge, m_Sub(m_Specific(PhiR),
2405-
m_ZExtOrSelf(m_ExplicitVectorLength(m_CombineOr(
2406-
m_Specific(PhiR),
2407-
// The AVL may be capped to a safe distance.
2408-
m_Select(m_VPValue(), m_Specific(PhiR),
2409-
m_VPValue()))))))) {
2404+
m_VPInstruction<Instruction::PHI>(
2405+
m_Specific(Plan.getTripCount()), m_VPValue(Backedge))) &&
2406+
match(Backedge,
2407+
m_VPInstruction<Instruction::Sub>(
2408+
m_Specific(PhiR),
2409+
m_ZExtOrSelf(
2410+
m_VPInstruction<VPInstruction::ExplicitVectorLength>(
2411+
m_CombineOr(
2412+
m_Specific(PhiR),
2413+
// The AVL may be capped to a safe distance.
2414+
m_Select(m_VPValue(), m_Specific(PhiR),
2415+
m_VPValue()))))))) {
24102416
AVLNext = Backedge;
24112417
}
24122418
}

0 commit comments

Comments
 (0)