[Mlir-commits] [mlir] [mlir][bufferization] Improve verifier for `bufferization.dealloc` (PR #67912)

Matthias Springer llvmlistbot at llvm.org
Sun Oct 1 05:09:22 PDT 2023


https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/67912

Check that the number of retained operands and updated conditions match.

>From 6e55928e1b34d66d867ce8452a9c9162c420fc7d Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Sun, 1 Oct 2023 14:08:16 +0200
Subject: [PATCH] [mlir][bufferization] Improve verifier for
 `bufferization.dealloc`

Check that the number of retained operands and updated conditions match.
---
 mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp | 3 +++
 mlir/test/Dialect/Bufferization/invalid.mlir           | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index 7c6c1be351cced1..d2823d17c99c88c 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -764,6 +764,9 @@ LogicalResult DeallocOp::verify() {
   if (getMemrefs().size() != getConditions().size())
     return emitOpError(
         "must have the same number of conditions as memrefs to deallocate");
+  if (getRetained().size() != getUpdatedConditions().size())
+    return emitOpError("must have the same number of updated conditions "
+                       "(results) as retained operands");
   return success();
 }
 
diff --git a/mlir/test/Dialect/Bufferization/invalid.mlir b/mlir/test/Dialect/Bufferization/invalid.mlir
index 3dfd1eb17e8d64f..8004ec632453e8c 100644
--- a/mlir/test/Dialect/Bufferization/invalid.mlir
+++ b/mlir/test/Dialect/Bufferization/invalid.mlir
@@ -87,3 +87,11 @@ func.func @invalid_dealloc_wrong_number_of_results(%arg0: memref<2xf32>, %arg1:
   %0:2 = bufferization.dealloc (%arg0, %arg1 : memref<2xf32>, memref<4xi32>) if (%arg2, %arg2) retain (%arg1 : memref<4xi32>)
   return %0#0 : i1
 }
+
+// -----
+
+func.func @invalid_dealloc_wrong_number_of_results(%arg0: memref<2xf32>, %arg1: memref<4xi32>, %arg2: i1) -> i1 {
+  // expected-error @below{{must have the same number of updated conditions (results) as retained operands}}
+  %0:3 = "bufferization.dealloc"(%arg0, %arg1, %arg2, %arg2, %arg1) <{operandSegmentSizes = array<i32: 2, 2, 1>}> : (memref<2xf32>, memref<4xi32>, i1, i1, memref<4xi32>) -> (i1, i1, i1)
+  return %0#0 : i1
+}



More information about the Mlir-commits mailing list