[Mlir-commits] [mlir] 672f1a0 - [mlir][memref] Make `LoadOp::verify` error more clear (#75831)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 18 09:41:09 PST 2023
Author: Rik Huijzer
Date: 2023-12-18T18:41:05+01:00
New Revision: 672f1a036a28cf993e7b5b022bd5582a8924ee58
URL: https://github.com/llvm/llvm-project/commit/672f1a036a28cf993e7b5b022bd5582a8924ee58
DIFF: https://github.com/llvm/llvm-project/commit/672f1a036a28cf993e7b5b022bd5582a8924ee58.diff
LOG: [mlir][memref] Make `LoadOp::verify` error more clear (#75831)
While debugging https://github.com/llvm/llvm-project/issues/71326, the
`LoadOp::verify` code and error were very confusing. This PR improves
that.
This code was a part from the reverted PR
https://github.com/llvm/llvm-project/pull/75519. Fixing the
`-convert-vector-to-scf` issue is going to take a bit longer and this
code was out of scope anyway.
Co-authored-by: Benjamin Maxwell <macdue at dueutil.tech>
Added:
Modified:
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
mlir/test/Dialect/MemRef/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index 93327a28234ea9..a332fe253ba645 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
@@ -1615,8 +1615,10 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
//===----------------------------------------------------------------------===//
LogicalResult LoadOp::verify() {
- if (getNumOperands() != 1 + getMemRefType().getRank())
- return emitOpError("incorrect number of indices for load");
+ if (static_cast<int64_t>(getIndices().size()) != getMemRefType().getRank()) {
+ return emitOpError("incorrect number of indices for load, expected ")
+ << getMemRefType().getRank() << " but got " << getIndices().size();
+ }
return success();
}
diff --git a/mlir/test/Dialect/MemRef/invalid.mlir b/mlir/test/Dialect/MemRef/invalid.mlir
index 55b759cbb3ce7c..f9b870f77266e1 100644
--- a/mlir/test/Dialect/MemRef/invalid.mlir
+++ b/mlir/test/Dialect/MemRef/invalid.mlir
@@ -896,6 +896,15 @@ func.func @bad_alloc_wrong_symbol_count() {
// -----
+func.func @load_invalid_memref_indexes() {
+ %0 = memref.alloca() : memref<10xi32>
+ %c0 = arith.constant 0 : index
+ // expected-error at +1 {{incorrect number of indices for load, expected 1 but got 2}}
+ %1 = memref.load %0[%c0, %c0] : memref<10xi32>
+}
+
+// -----
+
func.func @test_store_zero_results() {
^bb0:
%0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>
More information about the Mlir-commits
mailing list