You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Does this issue reproduce with the latest release?
Yes, also on tip.
What operating system and processor architecture are you using (go env)?
What did you do?
Simple test program.
What did you expect to see?
Comparable code or at least not dramatically worse code for cases where the compiler can figure out the address at compile time.
What did you see instead?
When the pointers used in each function can be determined at compile time to be a specific object's address, every access into the object uses LEAQ and the address is not saved or reused. When the compiler has to do a runtime computation (such as using a variable index into an array), or needs to create the address as its own object that lives somewhere anyway, such as to call a non-inlined function, it uses LEAQ to obtain the address once, and then just does accesses through that address, which turns out to be significantly faster.
Slightly modified version of the example on godbolt.org:
The fact that the LEAQ value is made each time in the loop instead of once before entering the loop is #15808.
The compiler has not yet been taught about the MOVBLZXloadidx1 instruction - that instruction would probably be even better here, as we don't need to materialize the LEAQ value at all.