<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75541>75541</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Flowing off the end of the function results in missed optimization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Eisenwave
</td>
</tr>
</table>
<pre>
```cpp
int map(int x) {
if (x == 0) return 0;
if (x == 1) return 1;
if (x == -1) return -1;
// return x;
}
```
[clang-trunk currently generates](https://godbolt.org/z/ednx94ada):
```asm
map(int): # @map(int)
mov eax, edi
test edi, edi
je .LBB0_4
cmp eax, 1
jne .LBB0_3
mov eax, 1
ret
.LBB0_3:
mov eax, -1
.LBB0_4:
ret
```
If one uncomments the last line in the function, the output is:
```asm
map(int): # @map(int)
mov eax, edi
ret
```
This is an odd case where the additional UB of flowing off the end of the function makes codegen worse.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VM-PqzYQ_muGyyiRMSbAgcNLU6RKPbbnyuCBeJ-xkW022f3rK0iym0TdVU8PIY39fd_88oBlCHqwRDXke8gPiZzj0fn6dx3InuQrJa1TbzXs2OXtpgnYAdgPbSOOcgJeLqsz8Aqh2F84RETdI_DyjJAdIDsgWwSe4uwtMsi-FqZ3wvQ74eZeubmTAm-ANzfm_EFAcbgubs1ct_m-M9IOm-hn-xO72Xuy0bzhQJa8jBQgPwAvjzFOAbIfl_iDU60zcev8ALx5B96QsudKSCWBV4vsMZcM4wX5OLSLDIFnCII9wB89L8_oXldL8gz8NySlH_lIIa7of5EvdLHbP_d79o94JLtxuo-cXtkXS3c-2bfVpI-sp3gBbr63c3j226T3OvGpew70NKw_enSWcLadG0eyMWA8EhoZIhptCbVdgX62XdTOLqmWvZvjNEfU4ZcM5qvi_zrqgDqgtOiUwk4GwtORPK01SqX0UrM0-PceXY-9cSdtB3R9vwrIqgW-7w9H-ZMCdk7RQBZPzgfaJqrOVJVVMqE6LRjPq0KIXXKsq6rcKZWVou_SQsqizJXIWMlzlbKe0jbRNWc8S3kqeCYE221LvmMpk63ieSuKrAXBaJTabI15HZdvP9EhzFQXeS7SxMiWTFhvEs4tnXAlgfPlYvH14rNp5yGAYEaHGD6jRB0N1c3_aNhTmE0My6BHHQIpdFPUo36XC53M3tRPP6qOx7nddm4E3iwJr2YzefdCXQTerGUG4M3axr8BAAD__5Dzb0Y">