-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[IR] Add matchers for remaining FP min/max intrinsics (NFC). #137612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: Florian Hahn (fhahn) ChangesAdd dedicated matchers for minimum,maximum,minimumnum and maximumnum intrinsics, similar for the existing matchers for maxnum and minnum. As suggested in #137335. Full diff: https://github.com/llvm/llvm-project/pull/137612.diff 3 Files Affected:
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 2d27c19e1b85e..40af76bcaf14e 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2747,12 +2747,36 @@ inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
}
+template <typename Opnd0, typename Opnd1>
+inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMinimum(const Opnd0 &Op0,
+ const Opnd1 &Op1) {
+ return m_Intrinsic<Intrinsic::minimum>(Op0, Op1);
+}
+
+template <typename Opnd0, typename Opnd1>
+inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty
+m_FMinimumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
+ return m_Intrinsic<Intrinsic::minimumnum>(Op0, Op1);
+}
+
template <typename Opnd0, typename Opnd1>
inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
const Opnd1 &Op1) {
return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
}
+template <typename Opnd0, typename Opnd1>
+inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMaximum(const Opnd0 &Op0,
+ const Opnd1 &Op1) {
+ return m_Intrinsic<Intrinsic::maximum>(Op0, Op1);
+}
+
+template <typename Opnd0, typename Opnd1>
+inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty
+m_FMaximumNum(const Opnd0 &Op0, const Opnd1 &Op1) {
+ return m_Intrinsic<Intrinsic::maximumnum>(Op0, Op1);
+}
+
template <typename Opnd0, typename Opnd1, typename Opnd2>
inline typename m_Intrinsic_Ty<Opnd0, Opnd1, Opnd2>::Ty
m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2) {
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index e7e0bef048f71..66ed8a036e146 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -784,17 +784,17 @@ RecurrenceDescriptor::isMinMaxPattern(Instruction *I, RecurKind Kind,
return InstDesc(Kind == RecurKind::FMin, I);
if (match(I, m_OrdOrUnordFMax(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMax, I);
- if (match(I, m_Intrinsic<Intrinsic::minnum>(m_Value(), m_Value())))
+ if (match(I, m_FMin(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMin, I);
- if (match(I, m_Intrinsic<Intrinsic::maxnum>(m_Value(), m_Value())))
+ if (match(I, m_FMax(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMax, I);
- if (match(I, m_Intrinsic<Intrinsic::minimumnum>(m_Value(), m_Value())))
+ if (match(I, m_FMinimumNum(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMinimumNum, I);
- if (match(I, m_Intrinsic<Intrinsic::maximumnum>(m_Value(), m_Value())))
+ if (match(I, m_FMaximumNum(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMaximumNum, I);
- if (match(I, m_Intrinsic<Intrinsic::minimum>(m_Value(), m_Value())))
+ if (match(I, m_FMinimum(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMinimum, I);
- if (match(I, m_Intrinsic<Intrinsic::maximum>(m_Value(), m_Value())))
+ if (match(I, m_FMaximum(m_Value(), m_Value())))
return InstDesc(Kind == RecurKind::FMaximum, I);
return InstDesc(false, I);
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4f6db05d18c2a..4d12f9d336e5b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -21838,9 +21838,9 @@ class HorizontalReduction {
if (match(I, m_Intrinsic<Intrinsic::minnum>(m_Value(), m_Value())))
return RecurKind::FMin;
- if (match(I, m_Intrinsic<Intrinsic::maximum>(m_Value(), m_Value())))
+ if (match(I, m_FMaximum(m_Value(), m_Value())))
return RecurKind::FMaximum;
- if (match(I, m_Intrinsic<Intrinsic::minimum>(m_Value(), m_Value())))
+ if (match(I, m_FMinimum(m_Value(), m_Value())))
return RecurKind::FMinimum;
// This matches either cmp+select or intrinsics. SLP is expected to handle
// either form.
@@ -23488,13 +23488,13 @@ static Instruction *getReductionInstr(const DominatorTree *DT, PHINode *P,
static bool matchRdxBop(Instruction *I, Value *&V0, Value *&V1) {
if (match(I, m_BinOp(m_Value(V0), m_Value(V1))))
return true;
- if (match(I, m_Intrinsic<Intrinsic::maxnum>(m_Value(V0), m_Value(V1))))
+ if (match(I, m_FMax(m_Value(V0), m_Value(V1))))
return true;
- if (match(I, m_Intrinsic<Intrinsic::minnum>(m_Value(V0), m_Value(V1))))
+ if (match(I, m_FMin(m_Value(V0), m_Value(V1))))
return true;
- if (match(I, m_Intrinsic<Intrinsic::maximum>(m_Value(V0), m_Value(V1))))
+ if (match(I, m_FMaximum(m_Value(V0), m_Value(V1))))
return true;
- if (match(I, m_Intrinsic<Intrinsic::minimum>(m_Value(V0), m_Value(V1))))
+ if (match(I, m_FMinimum(m_Value(V0), m_Value(V1))))
return true;
if (match(I, m_Intrinsic<Intrinsic::smax>(m_Value(V0), m_Value(V1))))
return true;
|
llvm/lib/Analysis/IVDescriptors.cpp
Outdated
return InstDesc(Kind == RecurKind::FMin, I); | ||
if (match(I, m_Intrinsic<Intrinsic::maxnum>(m_Value(), m_Value()))) | ||
if (match(I, m_FMax(m_Value(), m_Value()))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please rename these to F_Maxnum? Now that we have imported the full min-max zoo, we should be more explicit about this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I think I'll do this in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok turns out the matchers weren't used before this PR, so I pulled in the update here
Add dedicated matchers for minimum,maximum,minimumnum and maximumnum intrinsics, similar for the existing matchers for maxnum and minnum. As suggested in llvm#137335.
7fbbefd
to
834d1c4
Compare
Add dedicated matchers for minimum,maximum,minimumnum and maximumnum intrinsics, similar for the existing matchers for maxnum and minnum.
As suggested in #137335.