[Mlir-commits] [mlir] [mlir][linalg] do not break outs from block argument (PR #73572)
Mehdi Amini
llvmlistbot at llvm.org
Tue Nov 28 20:46:21 PST 2023
================
@@ -1818,6 +1818,11 @@ struct RemoveOutsDependency : public OpRewritePattern<GenericOp> {
if (sparse_tensor::getSparseTensorEncoding(operandVal.getType()))
continue;
+ // If outs is wired from a block argument, keep the dependency to
+ // prevent the argument from being optimized away.
----------------
joker-eph wrote:
Also, I had alluded to it before, but instead of just an attribute, using an op is actually a bit more robust to materialize your ABI:
```
func.func @my_add(%a: tensor<2xf32>, %b: tensor<2xf32>, %out: tensor<2xf32> { iree.abi.output : 0} -> tensor<2xf32> {
%r = linalg.generic ins(%a : tensor<2xf32>, %b : tensor<2xf32>) outs(%out) {
// add op
...
} -> tensor<2xf32>
%r_final = iree.tie_input_output %out, %r : tensor<2xf32>
return %r_final : tensor<2xf32>
}
```
This provides a clear guarantee that the `%out` isn't going away and express an "anchor" for a bufferization algorithm to force-alias `%out` and `%r` buffers.
https://github.com/llvm/llvm-project/pull/73572
More information about the Mlir-commits
mailing list