[Mlir-commits] [mlir] [mlir][Vector] Fold vector.constant_mask to SplatElementsAttr (PR #146724)
Kunwar Grover
llvmlistbot at llvm.org
Fri Jul 4 03:30:39 PDT 2025
================
@@ -6594,6 +6594,26 @@ bool ConstantMaskOp::isAllOnesMask() {
return true;
}
+static Attribute createBoolSplat(ShapedType ty, bool x) {
+ return SplatElementsAttr::get(ty, BoolAttr::get(ty.getContext(), x));
+}
+
+OpFoldResult ConstantMaskOp::fold(FoldAdaptor adaptor) {
+ ArrayRef<int64_t> bounds = getMaskDimSizes();
+ ArrayRef<int64_t> vectorSizes = getVectorType().getShape();
+ // Check the corner case of 0-D vectors first.
+ if (vectorSizes.size() == 0) {
+ assert(bounds.size() == 1 && "invalid sizes for zero rank mask");
+ return createBoolSplat(getVectorType(), bounds[0] == 1);
+ }
+ // Fold vector.constant_mask to splat if possible.
+ if (bounds == vectorSizes)
+ return createBoolSplat(getVectorType(), true);
+ if (llvm::all_of(bounds, [](int64_t x) { return x == 0; }))
----------------
Groverkss wrote:
i dont think so, i was hoping for something like llvm::all_zero, but all_of works
https://github.com/llvm/llvm-project/pull/146724
More information about the Mlir-commits
mailing list