Skip to content

Commit 672f1a0

Browse files
rikhuijzerMacDue
andauthored
[mlir][memref] Make LoadOp::verify error more clear (#75831)
While debugging #71326, the `LoadOp::verify` code and error were very confusing. This PR improves that. This code was a part from the reverted PR #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@dueutil.tech>
1 parent 3aa5d71 commit 672f1a0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,10 @@ GetGlobalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
16151615
//===----------------------------------------------------------------------===//
16161616

16171617
LogicalResult LoadOp::verify() {
1618-
if (getNumOperands() != 1 + getMemRefType().getRank())
1619-
return emitOpError("incorrect number of indices for load");
1618+
if (static_cast<int64_t>(getIndices().size()) != getMemRefType().getRank()) {
1619+
return emitOpError("incorrect number of indices for load, expected ")
1620+
<< getMemRefType().getRank() << " but got " << getIndices().size();
1621+
}
16201622
return success();
16211623
}
16221624

mlir/test/Dialect/MemRef/invalid.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,15 @@ func.func @bad_alloc_wrong_symbol_count() {
896896

897897
// -----
898898

899+
func.func @load_invalid_memref_indexes() {
900+
%0 = memref.alloca() : memref<10xi32>
901+
%c0 = arith.constant 0 : index
902+
// expected-error@+1 {{incorrect number of indices for load, expected 1 but got 2}}
903+
%1 = memref.load %0[%c0, %c0] : memref<10xi32>
904+
}
905+
906+
// -----
907+
899908
func.func @test_store_zero_results() {
900909
^bb0:
901910
%0 = memref.alloc() : memref<1024x64xf32, affine_map<(d0, d1) -> (d0, d1)>, 1>

0 commit comments

Comments
 (0)