Skip to content

[mlir][memref] Make LoadOp::verify error more clear #75831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2023
Merged

[mlir][memref] Make LoadOp::verify error more clear #75831

merged 1 commit into from
Dec 18, 2023

Conversation

rikhuijzer
Copy link
Member

@rikhuijzer rikhuijzer commented Dec 18, 2023

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.

@llvmbot
Copy link
Member

llvmbot commented Dec 18, 2023

@llvm/pr-subscribers-mlir-memref

@llvm/pr-subscribers-mlir

Author: Rik Huijzer (rikhuijzer)

Changes

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.

Since it was already reviewed, I'll merge once the PR checks succeeded.


Full diff: https://github.com/llvm/llvm-project/pull/75831.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp (+4-2)
  • (modified) mlir/test/Dialect/MemRef/invalid.mlir (+9)
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@+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>

@rikhuijzer rikhuijzer merged commit 672f1a0 into llvm:main Dec 18, 2023
@rikhuijzer rikhuijzer deleted the rh/loadop-verify-error branch December 18, 2023 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants