[llvm-dev] [Clang] memory allocation
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Tue Nov 26 06:15:00 PST 2019
On Tue, 26 Nov 2019 at 13:37, Mohammad Norouzi <mnmomn at gmail.com> wrote:
> But, why do they have different memory addresses when compiled with -O1?
> Is there a specific optimization that prevents using/reusing the same stack space?
The stack space is being reused, it just happens that those two
particular local variables don't get the same slot at higher
Each function has a bunch of registers it needs to preserve that go on
the stack, additional local spill slots for variables it wants to keep
around but doesn't have enough registers for, and the real declared
local variables. All three of those variables change with optimization
+ More efficient code might use fewer callee-saved registers,
leading to less saving at the beginning of a function.
+ More efficient use of values might get rid of the need to save
them for later, or leave registers free to hold them when needed.
+ Some local variables can be completely promoted to registers,
never using the stack at all.
And those changes very quickly mean that a specific local variable
will change its address.
More information about the llvm-dev