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

    <tr>
        <th>Summary</th>
        <td>
            [BUG][MLIR] expand-strided-metadata pass changes IR semantic
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          vlad-vinogradov-47
      </td>
    </tr>
</table>

<pre>
    The `expand-strided-metadata` pass has a pattern `RewriteExtractAlignedPointerAsIndexOfViewLikeOp`, which replaces `extract_aligned_pointer_as_index(view_like(%mem))` with `extract_aligned_pointer_as_index(%mem)`. But this pattern is not applicable for `memref.view` operation:

```mlir
func.func @test() -> index {
    %alloc = memref.alloc() : memref<64xi8>

    %offset_32 = index.constant 32
    %view = memref.view %alloc[%offset_32][] : memref<64xi8> to memref<4xi64>

    %intptr = memref.extract_aligned_pointer_as_index %view : memref<4xi64> -> index

    return %intptr : index
}

// RUN: mlir-opt -expand-strided-metadata

func.func @test() -> index {
    %alloc = memref.alloc() : memref<64xi8>
    %intptr = memref.extract_aligned_pointer_as_index %alloc : memref<64xi8> -> index
 return %intptr : index
}
```

`memref.view` specification:

> Returns a contiguous memref **with 0 offset** and empty layout.

Which means, that `memref.view` creates memref descriptor as:

```C++
dst.basePtr = src.BasePtr
dst.alignedPtr = src.alignedPtr + byte_shift
dst.offset = 0
```

So, in the above example `extract_aligned_pointer_as_index %view != extract_aligned_pointer_as_index %alloc` and the `expand-strided-metadata` pass performed non equal IR transformation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vdtu4zYQ_Rr6ZWCBoS6xHvRg51IE2HYXbrd9NChpZLFLkSo5sp2_Lyg5ayV12hQFCggyNJ4553BulN6rvUEsWLph6f1CDtRaVxy0rJcHZezeydoelsntorT1c_FLi8Ayjqdemnrpyaka62WHJGtJkmUceuk9tNK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