| Issue |
75541
|
| Summary |
Flowing off the end of the function results in missed optimization
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Eisenwave
|
```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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs