[LLVMdev] GetElementPtr

Ryan Taylor ryta1203 at gmail.com
Mon Dec 12 16:38:49 PST 2011

By LLVM do you mean the backend? I'm not using the backend, so is that i32
on the 0 index the type of the index value or the type of the value to
which exists at that index?

it seems the pointer itself has no width, it's arbitrary and is handled in
the lowering and is target dependent on the bus width.

Basically, when I am computing offset I need to know the sizes for add. The
size of the pointer (dedicated by bus width) and the size of the index.

A less confusing example (for me) might be this:

%idx2 = getelementptr i32* %MyVar, i64 1

The pointer type size is 32 bits (let's say int pointer), why is the
index of size 64?

On Mon, Dec 12, 2011 at 3:58 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> On Mon, Dec 12, 2011 at 3:54 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
> > For the gep:
> >
> > %idx1 = getelementptr i32* %MyVar, i32 0
> >
> > i32* is the type that MyVar is pointing to and i32 is the type of the
> offset
> > value, or what? If it's the type of offset value, then
> > the size of the pointer shouldn't be less than i32, correct?
> >
> >
> > The index is 0, so in this example, the address computation is idx1 =
> > &MyVar+0.
> >
> > What I want to know is the size in bits of the values above, it looks
> like 0
> > is 32 bits in size, which would make the pointer size also 32?
> LLVM will sign-extend or truncate the index to the size of the
> pointer; the pointer type could have any width.
> -Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111212/991fd06f/attachment.html>

More information about the llvm-dev mailing list