logoalt Hacker News

LtWorftoday at 7:26 AM1 replyview on HN

But what if whatever you call is also accessing and changing the attribute?


Replies

anematodetoday at 7:34 AM

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.

show 1 reply