I compiled the following code on MSVC 2013, x64, Release build with /02:
struct Point
{
int x;
int y;
};
Point xUnit()
{
Point p;
p.x = 1;
p.y = 0;
return p;
}
The generated assembly code for xUnit()
is:
mov QWORD PTR p$[rsp], 1
mov rax, QWORD PTR p$[rsp]
ret 0
Why does it write to the stack and then immediately read back into rax
to return?
I would have expected:
mov rax, 1
ret 0
X86 version seems to do well (that is generate "mov eax,1").
My guess is that X86 and X64 versions are separate code bases and optimization found in one target is not necessarily present in the other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With