From 932b9c681d3e1a4642c028683f7ca1676b9ef3c2 Mon Sep 17 00:00:00 2001 From: lipracer Date: Tue, 24 Jun 2025 06:29:19 +0000 Subject: [PATCH 1/2] [NFC][mlir][memref] refine debug message about memref::SubViewOp. --- mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp index d56b32193765e..3b001b9d1ea78 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -2917,27 +2917,32 @@ static bool haveCompatibleStrides(MemRefType t1, MemRefType t2, } static LogicalResult produceSubViewErrorMsg(SliceVerificationResult result, - Operation *op, Type expectedType) { + SubViewOp op, Type expectedType) { auto memrefType = llvm::cast(expectedType); switch (result) { case SliceVerificationResult::Success: return success(); case SliceVerificationResult::RankTooLarge: return op->emitError("expected result rank to be smaller or equal to ") - << "the source rank. "; + << "the source rank, but got:" << op.getType(); case SliceVerificationResult::SizeMismatch: return op->emitError("expected result type to be ") << expectedType - << " or a rank-reduced version. (mismatch of result sizes) "; + << " or a rank-reduced version. (mismatch of result sizes), but got:" + << op.getType(); case SliceVerificationResult::ElemTypeMismatch: return op->emitError("expected result element type to be ") - << memrefType.getElementType(); + << memrefType.getElementType() << ", but got:" << op.getType(); case SliceVerificationResult::MemSpaceMismatch: - return op->emitError("expected result and source memory spaces to match."); + return op->emitError( + "expected result and source memory spaces to match, but got:") + << op.getType(); case SliceVerificationResult::LayoutMismatch: return op->emitError("expected result type to be ") << expectedType - << " or a rank-reduced version. (mismatch of result layout) "; + << " or a rank-reduced version. (mismatch of result layout), but " + "got:" + << op.getType(); } llvm_unreachable("unexpected subview verification result"); } From 5f03ac1a4862ce62b228739a4fc86ca8abfe0148 Mon Sep 17 00:00:00 2001 From: lipracer Date: Tue, 24 Jun 2025 08:39:32 +0000 Subject: [PATCH 2/2] fix ir test --- mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | 10 +++++----- mlir/test/Dialect/MemRef/invalid.mlir | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp index 3b001b9d1ea78..6abf86564fc44 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -2924,24 +2924,24 @@ static LogicalResult produceSubViewErrorMsg(SliceVerificationResult result, return success(); case SliceVerificationResult::RankTooLarge: return op->emitError("expected result rank to be smaller or equal to ") - << "the source rank, but got:" << op.getType(); + << "the source rank, but got " << op.getType(); case SliceVerificationResult::SizeMismatch: return op->emitError("expected result type to be ") << expectedType - << " or a rank-reduced version. (mismatch of result sizes), but got:" + << " or a rank-reduced version. (mismatch of result sizes), but got " << op.getType(); case SliceVerificationResult::ElemTypeMismatch: return op->emitError("expected result element type to be ") - << memrefType.getElementType() << ", but got:" << op.getType(); + << memrefType.getElementType() << ", but got " << op.getType(); case SliceVerificationResult::MemSpaceMismatch: return op->emitError( - "expected result and source memory spaces to match, but got:") + "expected result and source memory spaces to match, but got ") << op.getType(); case SliceVerificationResult::LayoutMismatch: return op->emitError("expected result type to be ") << expectedType << " or a rank-reduced version. (mismatch of result layout), but " - "got:" + "got " << op.getType(); } llvm_unreachable("unexpected subview verification result"); diff --git a/mlir/test/Dialect/MemRef/invalid.mlir b/mlir/test/Dialect/MemRef/invalid.mlir index f908efb638446..42f89e76b3aa2 100644 --- a/mlir/test/Dialect/MemRef/invalid.mlir +++ b/mlir/test/Dialect/MemRef/invalid.mlir @@ -703,7 +703,7 @@ func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) { func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) { %0 = memref.alloc() : memref<8x16x4xf32> - // expected-error@+1 {{expected result element type to be 'f32'}} + // expected-error@+1 {{expected result element type to be 'f32', but got 'memref<8x16x4xi32>'}} %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1] : memref<8x16x4xf32> to memref<8x16x4xi32> @@ -714,10 +714,10 @@ func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) { func.func @invalid_subview(%arg0 : index, %arg1 : index, %arg2 : index) { %0 = memref.alloc() : memref<8x16x4xf32> - // expected-error@+1 {{expected result rank to be smaller or equal to the source rank.}} + // expected-error@+1 {{expected result rank to be smaller or equal to the source rank, but got 'memref<8x16x4x3xf32>'}} %1 = memref.subview %0[0, 0, 0][8, 16, 4][1, 1, 1] : memref<8x16x4xf32> to - memref<8x16x4x3xi32> + memref<8x16x4x3xf32> return }