[Mlir-commits] [mlir] [mlir][vector] Fix fold result for empty vector.mask with no results (PR #180345)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Feb 7 04:40:43 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-vector
Author: Longsheng Mou (CoTinker)
<details>
<summary>Changes</summary>
This PR fixes `foldEmptyMaskOp` to return `failure` when folding an empty vector.mask whose terminatorhas no operands. Previously this case returned success without producing any folded results, which violates the folding contract. Fixes #<!-- -->177825.
---
Full diff: https://github.com/llvm/llvm-project/pull/180345.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Vector/IR/VectorOps.cpp (+1-1)
- (modified) mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir (+11)
``````````diff
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 613adeb5eeaaf..089f41142dfd5 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -7614,7 +7614,7 @@ static LogicalResult foldEmptyMaskOp(MaskOp maskOp, MaskOp::FoldAdaptor adaptor,
auto terminator = cast<vector::YieldOp>(block->front());
if (terminator.getNumOperands() == 0) {
// `vector.mask` has no results, just remove the `vector.mask`.
- return success();
+ return failure();
}
// `vector.mask` has results, propagate the results.
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
index 319dfc31ab637..5655c76d37faf 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
@@ -772,3 +772,14 @@ func.func @arith_truncf(%arg0: f64) -> f16 {
return %truncd1 : f16
}
+
+// -----
+
+// Ensure that vector.mask with an empty mask does not cause issues.
+
+// CHECK-LABEL: empty_vector_mask
+func.func @empty_vector_mask(%mask : vector<8xi1>) {
+ // CHECK: vector.mask
+ vector.mask %mask { vector.yield } : vector<8xi1>
+ return
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180345
More information about the Mlir-commits
mailing list