Skip to content

Commit 8f36135

Browse files
committed
[VPlan] Add m_Intrinsic matcher that takes a variable intrinsic ID (NFC)
Add a variant of m_Intrinsic that matches a variable runtime ID.
1 parent 2e655c2 commit 8f36135

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

llvm/lib/Transforms/Vectorize/VPlanConstruction.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -845,23 +845,13 @@ bool VPlanTransforms::handleMaxMinNumReductions(VPlan &Plan) {
845845
if (!MinMaxR)
846846
return nullptr;
847847

848-
auto *RepR = dyn_cast<VPReplicateRecipe>(MinMaxR);
849-
if (!isa<VPWidenIntrinsicRecipe>(MinMaxR) &&
850-
!(RepR && isa<IntrinsicInst>(RepR->getUnderlyingInstr())))
848+
// Check that MinMaxR is a VPWidenIntrinsicRecipe or VPReplicateRecipe
849+
// with an intrinsic that matches the reduction kind.
850+
Intrinsic::ID ExpectedIntrinsicID =
851+
getMinMaxReductionIntrinsicOp(RedPhiR->getRecurrenceKind());
852+
if (!match(MinMaxR, m_Intrinsic(ExpectedIntrinsicID)))
851853
return nullptr;
852854

853-
#ifndef NDEBUG
854-
Intrinsic::ID RdxIntrinsicId =
855-
RedPhiR->getRecurrenceKind() == RecurKind::FMaxNum ? Intrinsic::maxnum
856-
: Intrinsic::minnum;
857-
assert(((isa<VPWidenIntrinsicRecipe>(MinMaxR) &&
858-
cast<VPWidenIntrinsicRecipe>(MinMaxR)->getVectorIntrinsicID() ==
859-
RdxIntrinsicId) ||
860-
(RepR && cast<IntrinsicInst>(RepR->getUnderlyingInstr())
861-
->getIntrinsicID() == RdxIntrinsicId)) &&
862-
"Intrinsic did not match recurrence kind");
863-
#endif
864-
865855
if (MinMaxR->getOperand(0) == RedPhiR)
866856
return MinMaxR->getOperand(1);
867857

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
856856
return IntrinsicID_match(IntrID);
857857
}
858858

859+
/// Match intrinsic calls with a runtime intrinsic ID.
860+
inline IntrinsicID_match m_Intrinsic(Intrinsic::ID IntrID) {
861+
return IntrinsicID_match(IntrID);
862+
}
863+
859864
template <Intrinsic::ID IntrID, typename T0>
860865
inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
861866
return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));

0 commit comments

Comments
 (0)