[llvm] [SCEVPatternMatch] Extend with more matchers (PR #138836)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 08:30:51 PDT 2025


================
@@ -93,6 +95,41 @@ struct specificscev_ty {
 /// Match if we have a specific specified SCEV.
 inline specificscev_ty m_Specific(const SCEV *S) { return S; }
 
+template <typename Class> struct cst_match {
+  Class CV;
+
+  cst_match(Class Op0) : CV(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() == CV;
+  }
+};
+
+/// Match an SCEV constant with a plain unsigned integer.
+inline cst_match<uint64_t> m_SCEVConstant(uint64_t V) { return V; }
----------------
nikic wrote:

```suggestion
inline cst_match<uint64_t> m_scev_SpecificInt(uint64_t V) { return V; }
```

https://github.com/llvm/llvm-project/pull/138836


More information about the llvm-commits mailing list