<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/57673>57673</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Crash in the x86 LEA optimization pass
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kazutakahirata
</td>
</tr>
</table>
<pre>
Build a compiler at 23dec4a3524aa5c9cc3cb401987014c6c5ee9de0 for x86-64.
Compile the attached test case with the resulting compiler on a x86-64 machine:
```
$ clang -O3 -S reduced.ll -o reduced.s
```
You'll encounter:
```
clang: /.../llvm/lib/Target/X86/X86OptimizeLEAs.cpp:695: bool (anonymous
namespace)::X86OptimizeLEAPass::removeRedundantLEAs((anonymous namespace)::X86OptimizeLEAPass::MemOpMap &):
Assertion `MRI->use_empty(LastVReg) && "The LEA's def register must have no uses"' failed.
```
I've posted an analysis and possible fix at https://reviews.llvm.org/D133631
The revisions after the aforementioned revision do not trigger the bug, but I don't think the underlying issue has gone away.
[reduced.txt](https://github.com/llvm/llvm-project/files/9541193/reduced.txt)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVU9FupDgQ_Bp4sQaBwczwwMNsspEibZRTLjrtPZ0a3APeAEbYTDL79VdAsslKp9WthGzA3dXV1eXK6kv5aTadFiRq24-m40mQFzLVXGeUKpkRqbqo67SusjgpDvs4yeq8VsyF5lic7CReDvkuz6Igvg7i47ZebVjCtww4T3XLWnh2XtTkWDwb365nE7u582Zo3qvbAVw2SNEj0QwcpMeP4EEevz7bp8xE3REwdvep2P0JUD3XrKOuEzv748v9d_K6_m3nQO4Rz0Nt58Hz9OuSazmEiEDeRFGEtevO_bKZCusjTQ17vHw95Nt6P3rTm-_85fPRRfU4Ijcv1IJQWdsB5kCDHS69nV9pDtSzG6nmQBYLl_T4M8of5Nz2f-LenvkBXQ6aBr9UANxHRPH_we64vx_vaASj_DV4pXN0jidvMBtocPdwuwvSz7Pjf7gf_QW1vpDzfz1wg5wtNccmHzFhwENaJzSfMIrGOIgr-hlOaOnMYrACOGAsESVOBAvo6BeTukUY0kYLHJgWXhmouzjj8KKX385U8N3JvCw2br0f187kDZ6Jz4afXbTMKrITyN5cJ2map8nHCo-rLc_GoVugnha-q41hde55WFRA6bcQoS2a8MJPpmleQ6sZ2FfYvLjF-QDOCICTn9ZjDIqn7rK43jg3M5RwogGqoGe6vHWvPr0517_4QF1D5Z_baXCJ5irCxfngP2y7cbLfuF78d4Kc0PamUFmSFOmqwTsm5ruWCrlM8lweUpXu01CXqS7SgkJvfMfl1USuFWZYmeNaLgMVdvMOrY4Y4Z5wnrryt-mt3S_81D5H5basTjpPCo6zTKmDlor2B1Y6VxXFuipUGnZUcedKiAPHDPy8Cbi4R12HppSxlHGRxMkhkyqNZL0niknJnHXCLIMs5h4W--GAcCpXShiYw2EHd77bI0RfphmY13LAp9m3diqf6Pvs6YlaM5GncGVQrh38C0wcprA">