[Mlir-commits] [mlir] [mlir][bufferization] Buffer deallocation: Make op preconditions stricter (PR #75127)

Matthias Springer llvmlistbot at llvm.org
Tue Dec 19 23:32:50 PST 2023


matthias-springer wrote:

> Another tricky case would be ops that sometimes allocate and sometimes don't. This is something that we do not support properly at the moment.
> 
> ```mlir
> // With a probability of 40%: %0 = %m
> // With a probability of 60%: %0 is a new allocation
> %0 = test.probabilistic_alloc {p = 0.4 : f32} %m : memref<?xf32>
> ```
> 
> Such an op would have to declare an `Allocate` side effect. I think side effects are a "maybe" property. False positives are allowed in `getEffects`. I guess this is somewhat of an edge case. But we could support such cases correctly by requiring that ops with an `Allocate` side effect to implement the `BufferDeallocationOpInterface`, which can then be queried to build the ownership indicator.
> 
> (In the example above, without further knowledge about the op, `BufferDeallocationOpInterface::materializeUniqueOwnershipForMemref` could compare the pointers of `%0` and `%m`. If they are the same, we take the ownership indicator of `%m`. Otherwise, `%true`.)
> 
> @maerhart Does this make sense?

I am going to prepare a change that adds "maybe side effects", wich should address the ""may allocate" issue: https://discourse.llvm.org/t/how-to-model-maybe-side-effects/75674. (This may take a while...)


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


More information about the Mlir-commits mailing list