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

    <tr>
        <th>Summary</th>
        <td>
            Miscompile in GVN due to MemDepAnalysis caching
        </td>
    </tr>

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

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

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

<pre>
    The following miscompile was uncovered in GVN, to reproduce:
`opt --passes=gvn  gvntest.ll` on [gvntest.ll.txt](https://github.com/user-attachments/files/17299256/gvntest.ll.txt)

The miscompiled output is: 
[testafterbad.ll.txt](https://github.com/user-attachments/files/17299260/testafterbad.ll.txt)

It appears that if the cache entry is cleared at MemoryDependenceAnalysis.cpp:1060 with `NonLocalPointerDeps.erase(CacheKey);` before the insert, the test is correct.
The resulting IR with this change: 
[testaftergood.ll.txt](https://github.com/user-attachments/files/17299268/testaftergood.ll.txt)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysU8Fu4zgM_Rr5QsSQ6dh1Dj4kDbIodlssFou5KzJtayBLhkQnk78fyG2RFijm1IsFWOLj43t8KkYzOKJWVAdRHTO18OhDq6xxKmZn393a_0eC3lvrr8YNMJmo_TQbS3BVERan_YUCdWAc_PXjReAjsIdAc_DdokmUeyGPQu5FLf3MsNnMKkaKojwOFwcwXBxT5NxaUUvwDkR1uP_L-ReL6iiwGZnnmMDwJPA0GB6Xc679JPC0RAobxaz0OJHjKPDUG0vpLB5wt8OqTiWfQXH3Rmv9phHvg3XgF54XBpM6wtvD6pDqVc8Uzqr7NnK1FHj6CvkzwycGNc-kQgQeFYPpgUcCrfRIQI7DDUwEbUklLxTDM00-3I40k-vIado7ZW_RxFzPsyj3hawlXA2PIGr54t0_Xiv7rzeOKRxpjjkFFUlg85g6_E23xKc8JJPO1PtAa3vjIgVePR8J0hQrCx8Cac7v2gaKi-W0Pk__vXblMT0clRvoa40H779R5OajyB-h31XOurbsduVOZdQWD9hssSgRs7HdNg3WGuuqLiqkvlIKO42lKrEpq35XZaZFidtCygYLiVLmTS8lkVY9dlus653YSpqUsbm1lyn3YchMjAu1RVFUTZVZdSYb1_whOrrCeisQUxxDm4o252WIYiutiRzvMGzYUvt8D-RrBKFbKGXwmaYjze--r6ti3JAtwbZ_0DKhvx2bOfifpFngaeW06vlK-tLi7wAAAP__FlNf8A">