[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; }
+
+struct bind_cst_ty {
+  const APInt *&CR;
+
+  bind_cst_ty(const APInt *&Op0) : CR(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);
+    if (!C)
+      return false;
+    CR = &C->getAPInt();
+    return true;
+  }
+};
+
+/// Match an SCEV constant and bind it to an APInt.
+inline bind_cst_ty m_SCEVConstant(const APInt *&C) { return C; }
----------------
nikic wrote:

```suggestion
inline bind_cst_ty m_scev_APInt(const APInt *&C) { return C; }
```

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


More information about the llvm-commits mailing list