<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57071>57071</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            one-shot-bufferize assertion error with bufferization.to_memref
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          srcarroll
      </td>
    </tr>
</table>

<pre>
    The `one-shot-bufferize` with and without pass throws assertion error `OpOperand was already decided to bufferize inplace` with the following IR
```
func.func @main(%arg0 : tensor<f32>) -> memref<f32> {
    %0 = bufferization.to_memref %arg0 : memref<f32>
    return %0 : memref<f32>
}
```
Although the pass succeeds with the `bufferize-function-boundaries` option, this is a bug.
Moreover, on more complex IR (see below) the same assertion error occurs with the `bufferize-function-boundaries`.
```
module attributes {tf.versions = {bad_consumers = [], min_consumer = 0 : i32, producer = 1099 : i32}} {
  func.func @main(%arg0: tensor<1x4x16xf32>, %arg1: tensor<1x4xi32>) -> tensor<2x16xf32> attributes {tf.entry_function = {control_outputs = "", inputs = "args_0,args_0_1", outputs = "Identity"}} {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c4 = arith.constant 4 : index
    %c16 = arith.constant 16 : index
    %cst = arith.constant dense<0.000000e+00> : tensor<2x16xf32>
    %0 = bufferization.to_memref %cst : memref<2x16xf32>
    %1 = memref.alloc() : memref<2x16xf32>
    memref.copy %0, %1 : memref<2x16xf32> to memref<2x16xf32>
    scf.for %arg2 = %c0 to %c4 step %c1 {
      %3 = tensor.extract %arg1[%c0, %arg2] : tensor<1x4xi32>
      %4 = arith.index_cast %3 : i32 to index
      scf.for %arg3 = %c0 to %c16 step %c1 {
        %5 = memref.load %1[%4, %arg3] : memref<2x16xf32>
        %6 = tensor.extract %arg0[%c0, %arg2, %arg3] : tensor<1x4x16xf32>
        %7 = arith.addf %5, %6 : f32
        memref.store %7, %1[%4, %arg3] : memref<2x16xf32>
      }
    }
    %2 = bufferization.to_tensor %1 : memref<2x16xf32>
    return %2 : tensor<2x16xf32>
  }
}
```
Also, it doesn't seem like the `dialect-filter` filter option 
Finally, if anyone has advice for how this should be transformed further before using `one-shot-bufferize` I'd appreciate the feedback.  Thanks!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVltvqzgQ_jXkxQoCEwh54KFttlIfVkdanffI4CHx1mBkmzbZX79jA7k0oWfPVqgBz_2bGc-Uip-KnwcgQRapFpbmoOyy7OsatPgH8JB8CnsgrOX-RfWWdMwYYg9afRqCr6CtUC0BrZV2Wn50PzrQXoAhg9TA-IlwqAQHTqwiZ-1EtJ1k1cWKRT9qJaX6FO2evP0VRNsgekLy-PjPum-r0P0jwSpqmGgDmgc0ZXofkSB5IhZao3SQvNQJDZI_ArohS_wlDTQa6vM5CdbPg0KCf6jASW_PzjEXVGjVbhAj1xa-aLpo0WB73U7KZhiD9fZhXE_SwbsfUPAYm76qALi5gIPMZ_SWDgPn5bJUfcuZFmAckqpzhwF9QQlhCD4Mo9qHg5U_lQb1AdrRMWsNfpJKNZ2EIwKOrucGgJSAOXDIOaOGNXCXaFVVvf49z8KHYTeK9xL1W6tF2VswLjG2DtFHgyqMzwoelYzvKvzuGyQMh-lzkG5dII1ozzRPGuAXiDpSO40mqpESR5vNmYiZWG-vC-Gb2roprfi4OsbZcaqwl7E84jsmcVuDZxq9iN-HDq3Vp90E4gQABmi1kjtswa63IwSU-ufFtdLVIfpidhGeDy-7eOT6IvvG0ZSwJ0e9w8I3RTV0BabQHkIHsWWtneBtORxvueNH3PEc9-oR92pWd_ZQeTbHb-wjfozYACYgCiP_BwF9jiJ_H1zn7io_v3dJDGavWn9O0wDVwBYyvPMqX2ub_yA9ClWqO3mfxgKMZ0Xdrfu9SlPVYe3ub1_HdCwQl34UHXJlLHRTkq-rxEeTeIkBvhCOVrPKnpsC-9SpuvQJxb4lc71yq_i6Rn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