Description
Repro:
int Test()
{
var a = new A().X;
return 1 + a;
}
struct A
{
public int X { get; }
}
Codegen:
push rax
xor eax, eax
mov [rsp], rax
lea rax, [rsp]
xor edx, edx
mov [rax], edx
mov eax, [rax]
inc eax
add rsp, 8
ret
But if I change the code to:
int Test()
{
var a = new A();
return 1 + a.X;
}
struct A
{
public int X { get; }
}
The codegen will become:
I think JIT should recognize patterns like: initobj - call - stloc - ldloc
Also applies to method calls.
Configuration
.NET 6 Preivew 6
Description
Repro:
Codegen:
But if I change the code to:
The codegen will become:
I think JIT should recognize patterns like:
initobj-call-stloc-ldlocAlso applies to method calls.
Configuration
.NET 6 Preivew 6