Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6901,11 +6901,12 @@ static bool planContainsAdditionalSimplifications(VPlan &Plan,
// Unused FOR splices are removed by VPlan transforms, so the VPlan-based
// cost model won't cost it whilst the legacy will.
if (auto *FOR = dyn_cast<VPFirstOrderRecurrencePHIRecipe>(&R)) {
if (none_of(FOR->users(), [](VPUser *U) {
auto *VPI = dyn_cast<VPInstruction>(U);
return VPI && VPI->getOpcode() ==
VPInstruction::FirstOrderRecurrenceSplice;
}))
using namespace VPlanPatternMatch;
if (none_of(
FOR->users(),
match_fn(
m_VPInstruction<VPInstruction::FirstOrderRecurrenceSplice>(
m_VPValue(), m_VPValue()))))
Comment on lines +6908 to +6909
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for use cases such as this, it would be convenient if we could match w/o arguments, just the opcode, as this is now less compact

return true;
}
// The VPlan-based cost model is more accurate for partial reduction and
Expand Down
13 changes: 13 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ template <typename Pattern> bool match(VPUser *U, const Pattern &P) {
return R && match(R, P);
}

template <typename Val, typename Pattern> struct VPMatchFunctor {
const Pattern &P;
VPMatchFunctor(const Pattern &P) : P(P) {}
bool operator()(Val *V) const { return match(V, P); }
};

/// A match functor that can be used as a UnaryPredicate in functional
/// algorithms like all_of.
template <typename Val = VPUser, typename Pattern>
VPMatchFunctor<Val, Pattern> match_fn(const Pattern &P) {
return P;
}

template <typename Class> struct class_match {
template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
};
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,11 +1149,10 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
CmpPredicate Pred;
if (match(A, m_Cmp(Pred, m_VPValue(), m_VPValue()))) {
auto *Cmp = cast<VPRecipeWithIRFlags>(A);
if (all_of(Cmp->users(), [&Cmp](VPUser *U) {
return match(U, m_CombineOr(m_Not(m_Specific(Cmp)),
m_Select(m_Specific(Cmp), m_VPValue(),
m_VPValue())));
})) {
if (all_of(Cmp->users(),
match_fn(m_CombineOr(
m_Not(m_Specific(Cmp)),
m_Select(m_Specific(Cmp), m_VPValue(), m_VPValue()))))) {
Cmp->setPredicate(CmpInst::getInversePredicate(Pred));
for (VPUser *U : to_vector(Cmp->users())) {
auto *R = cast<VPSingleDefRecipe>(U);
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Vectorize/VPlanVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ bool VPlanVerifier::verifyEVLRecipe(const VPInstruction &EVL) const {
}
// EVLIVIncrement is only used by EVLIV & BranchOnCount.
// Having more than two users is unexpected.
using namespace llvm::VPlanPatternMatch;
if ((I->getNumUsers() != 1) &&
(I->getNumUsers() != 2 || none_of(I->users(), [&I](VPUser *U) {
using namespace llvm::VPlanPatternMatch;
return match(U, m_BranchOnCount(m_Specific(I), m_VPValue()));
}))) {
(I->getNumUsers() != 2 ||
none_of(I->users(), match_fn(m_BranchOnCount(m_Specific(I),
m_VPValue()))))) {
errs() << "EVL is used in VPInstruction with multiple users\n";
return false;
}
Expand Down