[Mlir-commits] [mlir] [mlir][linalg] Add more precise memory effects to linalg op (PR #92079)

donald chen llvmlistbot at llvm.org
Thu May 23 05:29:17 PDT 2024


================
@@ -289,6 +289,9 @@ def MapOp : LinalgStructuredBase_Op<"map", [
 
     bool payloadUsesValueFromOperand(OpOperand * opOperand) {
       if (isDpsInit(opOperand)) return false;
+      if (getOperation()->getRegion(0).empty()) {
+        return true;
+      }
----------------
cxy-1993 wrote:

> Why does this lead to a crash?

When the cloneWithoutRegions function is called, the bufferize rewriter will invoke the notifyOperationInserted function. This function will query the side effects of the operation to count the number of memory allocations. Because this patch will call payloadUsesValueFromOperand when querying side effects, and the payloadUsesValueFromOperand of the map operation is implemented as follows:

```
bool payloadUsesValueFromOperand(OpOperand * opOperand) {                                                                                                                                  
   if (isDpsInit(opOperand)) return false;                                                                                                                                                                                                                                                                                                                     
  return !getMatchingBlockArgument(opOperand).use_empty();
}
```
This will fetch the block inside the op's region, causing a core dump.  

> Basically, the op is invalid without a region body. Generally speaking, helper functions on an op are allowed to function incorrectly if the op is invalid.

So should we prohibit querying side effects before the block is inserted?

https://github.com/llvm/llvm-project/pull/92079


More information about the Mlir-commits mailing list