[LLVMdev] alloca not in first bb behaving differently

David Chisnall David.Chisnall at cl.cam.ac.uk
Mon Apr 6 03:02:03 PDT 2015


On 5 Apr 2015, at 16:52, Dave Pitsbawn <dpitsbawn at gmail.com> wrote:
> 
> David why do you say it is particularly bad IR (other than not having gone through SROA).

If you place all of your allocas (other than ones for things like C VLAs in loops) at the start of the entry basic block and then use the lifetime markers for local variables with restricted scope, you make it much easier for the optimisers to handle the code.  For something this simple, it probably doesn't make a difference (I'd expect SROA + SimplifyCFG to optimise the whole thing away), but in more complex code having allocas outside of the first basic block can cause problems.

It's generally a good idea to keep around an IRBuilder with an insert point initialised to the start of the entry BB and use this to create allocas.

David





More information about the llvm-dev mailing list