From aed8f1992a3beba9f5b23bbd84af09e49e8e3375 Mon Sep 17 00:00:00 2001 From: "long.chen" Date: Fri, 27 Jun 2025 18:34:45 +0800 Subject: [PATCH] [NFC][mlir][memref] refine debug message about memref::SubViewOp. (#145470) --- mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | 17 +++++++++++------ mlir/test/Dialect/MemRef/invalid.mlir | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp index 372e83a98ee5..3c4d2562e699 100644 --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -2929,27 +2929,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"); } diff --git a/mlir/test/Dialect/MemRef/invalid.mlir b/mlir/test/Dialect/MemRef/invalid.mlir index 8e394b2ac04c..704cdaf838f4 100644 --- a/mlir/test/Dialect/MemRef/invalid.mlir +++ b/mlir/test/Dialect/MemRef/invalid.mlir @@ -713,7 +713,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> @@ -724,10 +724,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 }