[LLVMdev] mem2reg for non entry blocks?

Duncan Sands baldrick at free.fr
Tue Feb 26 06:06:45 PST 2013


Hi Justin,

>     an alloca outside of the entry block might be inside a loop, in which case the
>     semantics are that it would allocate more stack space on every loop iteration.
>     I think some of the optimizers that run later try to move allocas into the entry
>     block if possible, but in general it is simpler to have the front-end just put
>     them there in the first place.
>
>
> Mem2reg is already changing that semantic, though.  If I use an "alloca i32" in
> the entry block, then I am saying I want 4 bytes of stack space, but mem2reg may
> replace that with registers.

the problem isn't with mem2reg changing the amount of used stack space, it's
that those semantics get in the way of the mem2reg transform.  For example,
as you get new stack space each time round the loop, a write to the alloca
can't be retrieved by reading it back from the alloca next time round the
loop, because it isn't the same memory.  This is quite different to how things
work if the alloca is in the entry block.

Ciao, Duncan.



More information about the llvm-dev mailing list