[Mlir-commits] [mlir] [mlir][vector] Add an eliminate-vector-masks pass (PR #226517)

Dhairyashil R G llvmlistbot at llvm.org
Sat Sep 26 12:38:06 PDT 2026


================
@@ -11,6 +11,30 @@
 
 include "mlir/Pass/PassBase.td"
 
+def EliminateVectorMasks : Pass<"eliminate-vector-masks", "func::FuncOp"> {
+  let summary = "Replace masks that are provably all-true with constant masks";
+  let description = [{
+    Rewrites `vector.create_mask` operations that can be proven all-true into
+    `vector.constant_mask`. Canonicalization then folds those away, turning a
+    masked transfer into an unmasked one.
+
+    A mask dimension is all-true when its size is at least the size of the
+    corresponding vector dimension. Sizes are bounded with
+    `ValueBoundsOpInterface`, so sizes derived from a loop, such as
+    `%dim - %iv`, can be proven too.
+
+    Proving a scalable dimension needs the range of `vscale`: pass `vscale-min`
+    and `vscale-max` when it is known for the target (1 and 16 for SVE, say).
+    Without a range, only fixed-size dimensions can be proven.
+  }];
+  let options = [
+    Option<"vscaleMin", "vscale-min", "unsigned", /*default=*/"0",
+           "Minimum possible value of vscale, or 0 when unknown.">,
+    Option<"vscaleMax", "vscale-max", "unsigned", /*default=*/"0",
+           "Maximum possible value of vscale, or 0 when unknown.">,
+  ];
----------------
dhairyashilRG wrote:

Agreed. The error now shows the values and what is accepted:
`invalid vscale range 'vscale-min=0 vscale-max=4': expected both to be 0 (unknown), or both non-zero with 'vscale-min' <= 'vscale-max'`
I added this case to the test.

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


More information about the Mlir-commits mailing list