[LLVMdev] nested GEP in a static initializer fails

Joel E. Denny jdenny at etinternational.com
Mon Nov 1 14:22:24 PDT 2010


Hi Frits,

On Thu, 28 Oct 2010, Frits van Bommel wrote:

> On Thu, Oct 28, 2010 at 3:47 PM, Joel E. Denny
> <jdenny at etinternational.com> wrote:
> > For example, for my platform, llc folds the add but not the getelementptr
> > in:
> >
> >  @a = global i8* getelementptr (i8* null, i64 add (i64 3, i64 2))
> 
> This gets folded when it's read in; there's no other way to represent
> a constant 'i64 add (i64 3, i64 2)' in LLVM than 'i64 5'. (i.e. if you
> try to create the add() constant manually you get i64 5 automatically)

Thanks, I didn't realize this.

If I understand you correctly, then, in order to determine how my LLVM 
assembly will be handled, I must understand the internal LLVM API and data 
structures.  That is, I must understand what LLVM can represent so I can 
determine what will be folded, what the resulting expression will be, and 
thus whether the target assembly can represent the expression.

> As for transformation passes, grepping for
> ConstantFoldConstantExpression tells me that instruction combining
> (-instcombine) calls this method on all operands of instructions, and
> -globalopt seems to calls it on initializers of globals.

Ah, thanks.  Based on a few tests, it appears I can use more powerful 
constant expressions in LLVM assembly when I use opt -globalopt.  For 
example, nested GEPs do not produce assertion failures now.

I wonder if that assertion failure could be turned into an error message 
that suggests using "opt -globalopt".


More information about the llvm-dev mailing list