[llvm] [SCEVPatternMatch] Extend with more matchers (PR #138836)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 7 02:28:13 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Ramkumar Ramachandra (artagnon)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/138836.diff
1 Files Affected:
- (modified) llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h (+40)
``````````diff
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
index 900f6d0fd05ab..a073f45423dea 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
@@ -56,6 +56,16 @@ template <typename Class> struct class_match {
template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
};
+inline class_match<const SCEV> m_SCEV() { return class_match<const SCEV>(); }
+
+inline class_match<const SCEVConstant> m_SCEVConstant() {
+ return class_match<const SCEVConstant>();
+}
+
+inline class_match<const SCEVUnknown> m_SCEVUnknown() {
+ return class_match<const SCEVUnknown>();
+}
+
template <typename Class> struct bind_ty {
Class *&VR;
@@ -91,6 +101,25 @@ struct specificscev_ty {
/// Match if we have a specific specified SCEV.
inline specificscev_ty m_Specific(const SCEV *S) { return S; }
+template <typename Op0_t> struct cst_match {
+ Op0_t Op0;
+
+ cst_match(Op0_t Op0) : Op0(Op0) {}
+
+ bool match(const SCEV *S) const {
+ assert((isa<SCEVCouldNotCompute>(S) || !S->getType()->isVectorTy()) &&
+ "no vector types expected from SCEVs");
+ auto *C = dyn_cast<SCEVConstant>(S);
+ return C && C->getAPInt() == Op0;
+ }
+};
+
+/// Match an SCEV constant with an APInt.
+inline cst_match<APInt> m_SCEVConstant(const APInt &V) { return V; }
+
+/// Match an SCEV constant with a plain integer.
+inline cst_match<uint64_t> m_SCEVConstant(uint64_t V) { return V; }
+
/// Match a unary SCEV.
template <typename SCEVTy, typename Op0_t> struct SCEVUnaryExpr_match {
Op0_t Op0;
@@ -147,6 +176,17 @@ m_scev_Add(const Op0_t &Op0, const Op1_t &Op1) {
return m_scev_Binary<SCEVAddExpr>(Op0, Op1);
}
+template <typename Op0_t, typename Op1_t>
+inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>
+m_scev_Mul(const Op0_t &Op0, const Op1_t &Op1) {
+ return m_scev_Binary<SCEVMulExpr>(Op0, Op1);
+}
+
+template <typename Op0_t, typename Op1_t>
+inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>
+m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) {
+ return m_scev_Binary<SCEVUDivExpr>(Op0, Op1);
+}
} // namespace SCEVPatternMatch
} // namespace llvm
``````````
</details>
https://github.com/llvm/llvm-project/pull/138836
More information about the llvm-commits
mailing list