[LLVMdev] Is using lots of in-register values in IR bad?

Duncan Sands baldrick at free.fr
Fri Jul 29 02:24:47 PDT 2011

Hi Erkki,

> I want to experiment with avoiding mutable state as far as I can. At the moment
> there are no mutable variables -- only immutable value types (numerics, bool,
> vectors, tuples) and I've been doing everything in LLVM registers. The compiler
> doesn't generate a single alloca, load or store at the moment.
> I wonder if it was maybe a bad idea to do it this way? Because a lot of stuff in
> LLVM seem to be only available through pointers. e.g. extractvalue takes only
> constant indices, but GEP can take variables. Some things seem to be possible
> only by bitcasting pointers, e.g. splitting a Vector into equal-sized parts to
> partially compute the sum of it's elements with SIMD instructions...

splitting a vector can (and should) be done using the shufflevector instruction.

> And there may of course be some penalty for passing large(-ish) structures
> by-value.

In-register structs and arrays are not intended to be used for large structs and
arrays.  They are intended be used for small objects like complex numbers (two
elements), (pointer,size) pairs and so on.  Use memory (pointers) for anything

> Maybe a better alternative would be to allocate memory for every local value,
> and let the mem2reg pass optimize?

Most front-ends do that.  The dragonegg front-end is a bit different: it uses
registers directly for scalars and complex numbers, and memory for everything

Ciao, Duncan.

More information about the llvm-dev mailing list