Hacker News new | ask | show | jobs
by slavik81 1835 days ago
> the stack frame size is reserved once for all stack allocated variables when the function is called

Is there somewhere that's documented for LLVM? That's my expectation of what the final compiler output should be, but I read that the IR allocates every variable dynamically, and then they optimize away whatever they can. I haven't been able to figure out how or where it's guaranteed that all allocations will be coalesced.

I wouldn't normally worry about it, but I've talked to folks who don't believe me when I say it doesn't matter whether you declare an integer inside or outside of a loop. It would be nice to be able to explain exactly why it can never matter.

1 comments

I don't know LLVM well enough, but you can play with godbolt

By example, with https://godbolt.org/z/9Kv7oo9oK you can see that values goes into registers (and that thank to 'lea' there is not many registers used).

And if you remove the option -O2, values are spilled on stack.