[LLVMdev] mem2reg for non entry blocks?

Duncan Sands baldrick at free.fr
Tue Feb 26 02:42:43 PST 2013


Hi Vinod,

On 23/02/13 02:20, Vinod Grover wrote:
> Sorry if this has been discussed before, but I would appreciate any pointers.
> I am trying to understand why mem2reg only looks at allocas in entry blocks, and
> not for any allocas in a function. One case where allocas could be used to build
> local data structures like linked list (and so on make it unsafe), and for that
> the existing conditions in IsAllocaPromotable (i.e. the alloca pointer cannot
> escape or be stored or cast etc) should guard against that, regardless of the
> position of the alloca. right? Is there a reason for this?

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.

Ciao, Duncan.



More information about the llvm-dev mailing list