[llvm] 88a832a - Refactored the pattern matching.
Thomas Symalla via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 2 00:16:06 PST 2021
Author: Thomas Symalla
Date: 2021-02-02T09:14:52+01:00
New Revision: 88a832aef1a696178c2ec3cb93f913ac937c4f5e
URL: https://github.com/llvm/llvm-project/commit/88a832aef1a696178c2ec3cb93f913ac937c4f5e
DIFF: https://github.com/llvm/llvm-project/commit/88a832aef1a696178c2ec3cb93f913ac937c4f5e.diff
LOG: Refactored the pattern matching.
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
index c91462f9745a..59dcbea8dcf6 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h
@@ -491,47 +491,6 @@ m_Not(const SrcTy &&Src) {
return m_GXor(Src, m_AllOnesInt());
}
-template <typename Boundary1, typename Boundary2, typename Origin>
-struct maxmin_match_helper {
- Boundary1 B1;
- Boundary2 B2;
- Origin O;
-
- maxmin_match_helper(const Boundary1 &FirstBoundary,
- const Boundary2 &SecondBoundary, const Origin &Or)
- : B1(FirstBoundary), B2(SecondBoundary), O(Or) {}
-
- template <typename OpTy>
- bool match(const MachineRegisterInfo &MRI, OpTy &&Op) {
- CmpInst::Predicate Predicate1;
- Register Base;
-
- if (mi_match(Op, MRI,
- m_GISelect(m_GICmp(m_Pred(Predicate1), m_Reg(), m_Reg()),
- m_Reg(Base), B1))) {
- CmpInst::Predicate Predicate2;
-
- if (mi_match(Base, MRI,
- m_GISelect(m_GICmp(m_Pred(Predicate2), m_Reg(), m_Reg()), O,
- B2))) {
- if ((Predicate1 == CmpInst::ICMP_SLT &&
- Predicate2 == CmpInst::ICMP_SGT) ||
- (Predicate1 == CmpInst::ICMP_SGT &&
- Predicate2 == CmpInst::ICMP_SLT)) {
- return true;
- }
- }
- }
-
- return false;
- }
-};
-
-template <typename Boundary1, typename Boundary2, typename Origin>
-inline maxmin_match_helper<Boundary1, Boundary2, Origin>
-m_MaxMin(const Boundary1 &B1, const Boundary2 &B2, const Origin &O) {
- return maxmin_match_helper<Boundary1, Boundary2, Origin>(B1, B2, O);
-}
} // namespace MIPatternMatch
} // namespace llvm
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
index b7f3cd951af0..8996a45e5dd1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
@@ -283,9 +283,21 @@ bool AMDGPUPostLegalizerCombinerHelper::matchClampI64ToI16(
LLVM_DEBUG(dbgs() << "Matching Clamp i64 to i16");
- if (mi_match(MI.getOperand(1).getReg(), MRI,
- m_MaxMin(m_ICst(MatchInfo.Cmp1), m_ICst(MatchInfo.Cmp2),
- m_Reg(MatchInfo.Origin)))) {
+ CmpInst::Predicate Predicate1;
+ Register Base;
+
+ if (!mi_match(MI.getOperand(1).getReg(), MRI, m_GISelect(m_GICmp(m_Pred(Predicate1), m_Reg(), m_Reg()), m_Reg(Base), m_ICst(MatchInfo.Cmp1))))
+ return false;
+
+ CmpInst::Predicate Predicate2;
+
+ if (!mi_match(Base, MRI, m_GISelect(m_GICmp(m_Pred(Predicate2), m_Reg(), m_Reg()), m_Reg(MatchInfo.AssignValue), m_ICst(MatchInfo.Cmp2))))
+ return false;
+
+ if ((Predicate1 == CmpInst::ICMP_SLT &&
+ Predicate2 == CmpInst::ICMP_SGT) ||
+ (Predicate1 == CmpInst::ICMP_SGT &&
+ Predicate2 == CmpInst::ICMP_SLT)) {
const auto Cmp1 = MatchInfo.Cmp1;
const auto Cmp2 = MatchInfo.Cmp2;
const auto Diff = std::abs(Cmp2 - Cmp1);
@@ -298,7 +310,7 @@ bool AMDGPUPostLegalizerCombinerHelper::matchClampI64ToI16(
const int64_t Min = std::numeric_limits<int16_t>::min();
const int64_t Max = std::numeric_limits<int16_t>::max();
- // are we really trying to clamp against short boundaries?
+ // are we really trying to clamp against the relevant boundaries?
return ((Cmp2 >= Cmp1 && Cmp1 >= Min && Cmp2 <= Max) ||
(Cmp1 >= Cmp2 && Cmp1 <= Max && Cmp2 >= Min));
}
More information about the llvm-commits
mailing list