JIT: Unnecessary jump into definitly-executed loop body
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
https://www.godbolt.org/z/5b594qKd5
```cs
static int Upsilon(int a, int b)
{
int n = 100;
while (n > 0)
{
int t = a + b;
a = b;
b = t;
n = n - 1;
}
return a;
}
```
```assembly
Program:Upsilon(int,int):int (FullOpts):
mov eax, 100
jmp SHORT G_M57122_IG04
align [0 bytes for IG03]
G_M57122_IG03: ;; offset=0x0007
mov r8d, ecx
mov ecx, edx
mov edx, r8d
G_M57122_IG04: ;; offset=0x000F
add ecx, edx
dec eax
test eax, eax
jg SHORT G_M57122_IG03
mov ecx, edx
mov eax, ecx
ret
```
It emits an unconditional `jmp SHORT G_M57122_IG04` into the loop body at the start of the function.
Instead it could fall into it. For example, MSVC: https://godbolt.org/z/Pr5bTn999
Contributor guide
Assessment
This issue has not been assessed yet.