1. Import return cond; as return cond ? true : false
Expand expressions like
to
if (n == 42)
return true;
return false;
Early in the importer/morph so we can then properly merge returns, apply branch-to-cmov (or optOptimizeBool) kinds of optimizations. It's a sort of canonization, we then should convert it back to return cmp or even optimize to cmov/csel if necessary. It will allow us to forget about various ? true : false hacks in the codebase.
2. Duplicate returns for return GT_RET_EXPR
currently, when we inline a method under GT_RETURN node, e.g.:
static int Foo(int x)
{
return Bar(x);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static int Bar(int x)
{
if (x == 42)
return 10;
if (x <= 0)
return 0;
return 100;
}
We end up with 4 jmp instructions (while 2 would be enough) in the codegen of Foo:
; Assembly listing for method Program:Foo(int):int
cmp ecx, 42
jne SHORT G_M29289_IG04
mov eax, 10
jmp SHORT G_M29289_IG06
G_M29289_IG04:
test ecx, ecx
jg SHORT G_M29289_IG05
xor eax, eax
jmp SHORT G_M29289_IG06
G_M29289_IG05:
mov eax, 100
G_M29289_IG06:
ret
because we end up spilling Bar into a temp during inlining while we should just insert it as is and remove parent GT_RETURN
Expected codegen:
; Assembly listing for method Program:Foo(int):int
cmp ecx, 42
jne SHORT G_M8222_IG05
mov eax, 10
ret
G_M8222_IG05:
test ecx, ecx
jg SHORT G_M8222_IG07
xor eax, eax
ret
G_M8222_IG07:
mov eax, 100
ret
just two jumps. If epilogues are big or too many of them a separate phase should merge them.
category:implementation
theme:ir
1. Import
return cond;asreturn cond ? true : falseExpand expressions like
to
Early in the importer/morph so we can then properly merge returns, apply branch-to-cmov (or optOptimizeBool) kinds of optimizations. It's a sort of canonization, we then should convert it back to
return cmpor even optimize tocmov/cselif necessary. It will allow us to forget about various? true : falsehacks in the codebase.2. Duplicate returns for
return GT_RET_EXPRcurrently, when we inline a method under GT_RETURN node, e.g.:
We end up with 4
jmpinstructions (while 2 would be enough) in the codegen ofFoo:because we end up spilling
Barinto a temp during inlining while we should just insert it as is and remove parentGT_RETURNExpected codegen:
just two jumps. If epilogues are big or too many of them a separate phase should merge them.
category:implementation
theme:ir