-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone
Description
Repro:
static int Result(int i)
{
if (i < 4) return 0;
return i / 4;
}This results in:
; Method Program:<<Main>$>g__Result|0_0(int):int (FullOpts)
G_M000_IG01: ;; offset=0x0000
G_M000_IG02: ;; offset=0x0000
cmp ecx, 4
jge SHORT G_M000_IG05
G_M000_IG03: ;; offset=0x0005
xor eax, eax
G_M000_IG04: ;; offset=0x0007
ret
G_M000_IG05: ;; offset=0x0008
mov eax, ecx
sar eax, 31
and eax, 3
add eax, ecx
sar eax, 2
G_M000_IG06: ;; offset=0x0015
ret
; Total bytes of code: 22but as the JIT can prove that the i used in i / 4 isn't negative, so presumably it should be able to emit the code as if:
static int Result(int i)
{
if (i < 4) return 0;
return (int)((uint)i / 4);
}were instead used? And it results in:
; Method Program:<<Main>$>g__Result|0_0(int):int (FullOpts)
G_M000_IG01: ;; offset=0x0000
G_M000_IG02: ;; offset=0x0000
cmp ecx, 4
jge SHORT G_M000_IG05
G_M000_IG03: ;; offset=0x0005
xor eax, eax
G_M000_IG04: ;; offset=0x0007
ret
G_M000_IG05: ;; offset=0x0008
mov eax, ecx
shr eax, 2
G_M000_IG06: ;; offset=0x000D
ret
; Total bytes of code: 14Zintom, colejohnson66 and PaulusParssinen
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI