If I define static instance of a class, is there optimization in compilers (particularly g++/clang) to omit base
register (for this
calls) when data members accessed directly or indirectly (I mean [base + index * scale + displacement]
formula) and just use single displacement
constant for all of them? All member functions may became static (in case of sole instance of the class it is reasonable).
I can't check this, because on godbolt.org compiler aggressively optimizes following code to xor eax, eax; ret
:
struct A
{
int i;
void f()
{
++i;
}
};
static A a;
int main(int argc, char * argv[])
{
a.i = argc;
}