I'm playing around with link time optimization in Visual C++, whole program optimization (WPO) its called there. Specifically checking if MSVC inlines a one-liner function in another module.
so I have this function
Code:
int Bla::GetBla() { return m_x; }
and this main in another module, pretty simple
Code:
int main(int argc, char **argv)
{
Bla bla(std::rand());
int x = bla.GetBla();
cout << x << endl;
return 0;
}
When I turn on optimizations but no WPO I get the following assembler for the call to GetBla.
; 35 : int x = bla.GetBla();
lea ecx, DWORD PTR _bla$[esp+8]
call ?GetBla@Bla@@QAEHXZ; Bla::GetBla
push eax
asm for GetBla itself:
?GetBla@Bla@@QAEHXZ PROC; Bla::GetBla, COMDAT;
; 10 : return m_x;
mov eax, DWORD PTR [ecx]
With WPO turned on I get this:
; 35 : int x = bla.GetBla();
call ?GetBla@Bla@@QAEHXZ ; Bla::GetBla
push eax
asm for GetBla itself:
?GetBla@Bla@@QAEHXZ PROC; Bla::GetBla, COMDAT;
; 10 : return m_x;
mov eax, DWORD PTR [eax]
I don't understand the lea instruction before the call to GetBla in the version with WPO turned OFF. What's the use of that. And why doesn't it get emitted in the version with WPO turned ON?
Does anyone know?