I expect the if (i >= 0) branch to be removed, but it isn't.
Interestingly if I swap the upper bound (100) with a variable (bound) it does.
No godbolt link cause it's outdated (compiler-explorer/dotnet-builder#29)
static void Test(int bound)
{
for (int i = 0; i < 100; i++)
{
if (i >= 0)
{
Console.WriteLine("Hi");
}
}
}
G_M38621_IG01: ;; offset=0x0000
push rsi
push rbx
sub rsp, 40
;; size=6 bbWeight=1 PerfScore 2.25
G_M38621_IG02: ;; offset=0x0006
xor ebx, ebx
mov rsi, 0x232D5365040 ; 'Hi'
jmp SHORT G_M38621_IG05
align [0 bytes for IG03]
;; size=14 bbWeight=1 PerfScore 2.50
G_M38621_IG03: ;; offset=0x0014
inc ebx
;; size=2 bbWeight=16 PerfScore 4.00
G_M38621_IG04: ;; offset=0x0016
test ebx, ebx
jl SHORT G_M38621_IG03
;; size=4 bbWeight=32 PerfScore 40.00
G_M38621_IG05: ;; offset=0x001A
mov rcx, rsi
call [System.Console:WriteLine(System.String)]
inc ebx
cmp ebx, 100
jl SHORT G_M38621_IG04
;; size=16 bbWeight=8 PerfScore 38.00
G_M38621_IG06: ;; offset=0x002A
add rsp, 40
pop rbx
pop rsi
ret
;; size=7 bbWeight=1 PerfScore 2.25
I expect the
if (i >= 0)branch to be removed, but it isn't.Interestingly if I swap the upper bound (100) with a variable (
bound) it does.No godbolt link cause it's outdated (compiler-explorer/dotnet-builder#29)