<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63559>63559</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[GVN] Incorrect non-local load elimination
</td>
</tr>
<tr>
<th>Labels</th>
<td>
miscompilation,
llvm:GVN
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dantrushin
</td>
</tr>
</table>
<pre>
Attached test case demonstrates incorrect 'non-local' load elimination.
Basically, test does following:
```
for (i = ... ) {
array[2] += i;
array[3] += i;
array[3] *= -1802;
array[2] += i;
array[3] += i;
}
```
but with fancy CFG (and this fancy CFG is required to reproduce issue).
LLVM vectorizes increments of array[2:3] and then GVN removes second vector load not noticing that array[3] element was
updated between two loads.
(See BB `latch` where load `%val.array.2_3.3` is eliminated)
[gvn_nonlocal_dep.txt](https://github.com/llvm/llvm-project/files/11885737/gvn_nonlocal_dep.txt)
Attached test renamed to .txt from .ll
Also [Compiler explorer link](https://godbolt.org/z/MbzP6WY38)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE2P4zYM_TX0hRjDoeKvgw_JBBkU2F0UKDBFTwNFYmK1spRKcrIzv76wnZnutimKBRIEEZ_4-PgoyhjNyTF3UG6h3GVyTL0PnZYuhTH2xmUHr1-7TUpS9awxcUyoZGTUPHgXU5CJIxqnfAisEgLVzrsH65W0QDVaLzWyNYNxMhnvcih2UGy2MholrX0FelySas8Rj95afzXuBGKzAKEqbp_579EHBGoMgthhnucI1CLU2yWKKEOQr1BuCcodAm0nmAHxHn8Pi_vhf8Y3U_xh1RR0B_MfFP_DAfXurrDDmPBqUo9H6dQrPu6fJp3SaUy9id-cmoiB_xxNmNzwGPgcvB4Vo4lxZKD21uFPn54_44VV8sG8LRYFHtiliP74jQixmQtdmNjh0_MXDDz4C0eMrLzTtyyLlc6n6WuUcSdMvUzf62U7c-BVRlzqGM9aJtZ44HRldpiufs4U8xsAqPmFGbdbhKqwMqkeqgKvPQdeKKceUXmRNp-pcnoRuZgwJn5MFmug9pav3J4u7sV5Nw_hi-Zznr4mKHdATZ_SOU7DRXug_cmkfjzkyg9Ae2sv7z8P5-B_Z5WA9kdjOQLtV6umKWtRT7fuZX9n__6lBHZyWIyaUHgMfsDc2lulyw0bPUK5ffTD2VgOyF_P1gcOaI37427ZXh-8TbkPJ6D9G9D-8-Ht5-rX30QD1Ga6E7oVrcy4W1VN3TRN2Yis79b1Ua6VqFcrpkZIEkqpspGFUKpU7brNTEcFiaKielWXFYm85IMm3Va6qgqtqwLWBQ_S2Hxq0kSfzUPXVaIs28zKA9s4bxKiwUQ1C5pfPRABPQLR3GSxeXr-Mh2Vuyx0c8MP4ynCurAmpvh39mSSnVfThC93-NPHmvnYMf9aMNkYbPfDNs86Jp9nKX8FAAD__6uCkTk">