[Mlir-commits] [mlir] [mlir][Vector] add vector.insert canonicalization pattern for vectors created from ub.poison (PR #142944)

Yang Bai llvmlistbot at llvm.org
Thu Jun 26 02:06:07 PDT 2025


================
@@ -3191,6 +3227,114 @@ class InsertSplatToSplat final : public OpRewritePattern<InsertOp> {
   }
 };
 
+/// Pattern to optimize a chain of constant insertions into a poison vector.
+///
+/// This pattern identifies chains of vector.insert operations that:
+/// 1. Start from an ub.poison operation.
+/// 2. Insert only constant values at static positions.
+/// 3. Completely initialize all elements in the resulting vector.
----------------
yangtetris wrote:

If the vector didn't start from **ub.poison**, the existing [foldDenseElementsAttrDestInsertOp](https://github.com/llvm/llvm-project/blob/e9e25f02e6e10c75224aad646bdd1705f1d9d8b1/mlir/lib/Dialect/Vector/IR/VectorOps.cpp#L3300C1-L3300C34) in `InsertOp::fold` should already be able to handle the folding. However, it does not guarantee all elements are initialized. That’s why I want to add this new pattern explicitly targets **ub.poison**.

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


More information about the Mlir-commits mailing list