[Mlir-commits] [mlir] [MLIR][Vector] Move scalable dims check before IR creation in ScanToArithOps (PR #188954)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Mar 27 03:28:23 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Mehdi Amini (joker-eph)
<details>
<summary>Changes</summary>
ScanToArithOps::matchAndRewrite created the result arith.constant before checking whether the reduction dimension is scalable. When the dimension was scalable, the pattern returned notifyMatchFailure() after IR was already modified, violating MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS.
Fix: move the reductionScalableDims check to before the arith::ConstantOp creation.
Assisted-by: Claude Code
Fix a failure present with MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS=ON.
---
Full diff: https://github.com/llvm/llvm-project/pull/188954.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp (+6-3)
``````````diff
diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp
index 1af552362a26a..f3e239bedb7f7 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorScan.cpp
@@ -111,9 +111,6 @@ struct ScanToArithOps : public OpRewritePattern<vector::ScanOp> {
if (!isValidKind(isInt, scanOp.getKind()))
return failure();
- VectorType resType = destType;
- Value result = arith::ConstantOp::create(rewriter, loc, resType,
- rewriter.getZeroAttr(resType));
int64_t reductionDim = scanOp.getReductionDim();
bool inclusive = scanOp.getInclusive();
int64_t destRank = destType.getRank();
@@ -123,10 +120,16 @@ struct ScanToArithOps : public OpRewritePattern<vector::ScanOp> {
SmallVector<int64_t> reductionShape(destShape);
SmallVector<bool> reductionScalableDims(destType.getScalableDims());
+ // Check before creating any IR so that returning failure() does not
+ // violate the pattern API contract.
if (reductionScalableDims[reductionDim])
return rewriter.notifyMatchFailure(
scanOp, "Trying to reduce scalable dimension - not yet supported!");
+ VectorType resType = destType;
+ Value result = arith::ConstantOp::create(rewriter, loc, resType,
+ rewriter.getZeroAttr(resType));
+
// The reduction dimension, after reducing, becomes 1. It's a fixed-width
// dimension - no need to touch the scalability flag.
reductionShape[reductionDim] = 1;
``````````
</details>
https://github.com/llvm/llvm-project/pull/188954
More information about the Mlir-commits
mailing list