Unnecessary `mov eax, eax` generated only if there is a conditional branch.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
https://godbolt.org/z/48scbhEKo
Code
```c++
int eax();
unsigned long long x(int in) {
in |= eax();
if (in < 0) {
while (true) {}
}
return (unsigned long long)(unsigned)in;
}
unsigned long long y(int in) {
in |= eax();
return (unsigned long long)(unsigned)in;
}
```
Assembly
```asm
x(int):
push rbx
mov ebx, edi
call eax()@PLT
or eax, ebx
js .LBB0_1
mov eax, eax ; <---
pop rbx
ret
.LBB0_1:
jmp .LBB0_1
y(int):
push rbx
mov ebx, edi
call eax()@PLT
or eax, ebx
pop rbx
ret```
Contributor guide
Research direction
Start by reproducing the example at https://godbolt.org/z/48scbhEKo and compare the generated assembly for x and y. Trace the LLVM code-generation path responsible for the conditional branch and integer conversion; done means the unnecessary mov eax, eax is no longer emitted while the branch behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100