logoalt Hacker News

anematodetoday at 7:34 AM1 replyview on HN

If what you call gets inlined, then the compiler can see that it either does or doesn't modify the attribute and optimize it accordingly. Even virtual calls can often be inlined via, e.g., class hierarchy analysis and inline caches.

If these analyses don't apply and the callee could do anything, then of course the compiler can't keep the value hoisted. But a function call has to occur anyway, so the hoisted value will be pushed/popped from the stack and you might as well reload it from the object's field anyway, rather than waste a stack slot.


Replies

LtWorftoday at 2:19 PM

Another thread can access it and do that, how could the compiler possibly know about it?

show 1 reply