[llvm] [InstCombine] Constant fold binops through `vector.insert` (PR #164624)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 23 05:33:51 PDT 2025


================
@@ -198,6 +198,25 @@ struct constantexpr_match {
 /// expression.
 inline constantexpr_match m_ConstantExpr() { return constantexpr_match(); }
 
+template <typename SubPattern_t> struct Splat_match {
+  SubPattern_t SubPattern;
+  Splat_match(const SubPattern_t &SP) : SubPattern(SP) {}
+
+  template <typename OpTy> bool match(OpTy *V) const {
+    if (auto *C = dyn_cast<Constant>(V)) {
+      auto *Splat = C->getSplatValue();
+      return Splat ? SubPattern.match(Splat) : false;
+    }
+    // TODO: Extend to other cases (e.g. shufflevectors).
+    return false;
+  }
+};
+
+/// Match a splat. This is currently limited to constant splats.
+template <typename T> inline Splat_match<T> m_Splat(const T &SubPattern) {
----------------
nikic wrote:

This should either be `m_ConstantSplat` or support non-constant splats (what `getSplatValue` in VectorUtils does).

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


More information about the llvm-commits mailing list