[LLVMdev] getelementptr and SCEVs

Dan Gohman djg at cray.com
Thu Mar 1 09:43:39 PST 2007


On Fri, Feb 23, 2007 at 06:34:47PM -0800, Chris Lattner wrote:
> On Fri, 23 Feb 2007, Dan Gohman wrote:
> > Does anyone have any suggestions on the best way to procede? It may be
> > easier at this point to go back to a multiple-index getelementptr SCEV
> > class, and just write the code to work with it.
> 
> It really depends on what you're trying to do.  Can you say what 
> optimization of code xform you're trying to accomplish?

Well, primarily I'm just trying to learn a few things :-).
At the moment I'm working on a pass to do simple prefetching, using SCEVs
to look at how the addresses of load instructions evolve in loops. Beyond
that, I'm interested in looking at loop memory footprints in general.

> As I mentioned before, SCEV is really designed for integer expressions, 
> not pointer expressions.  Fortunately, all pointers can be treated as 
> integers, and GEP is really just doing some integer arithmetic.  Given 
> something like this:
> 
> P = getelementptr i32* %A, i32 %Idx
> 
> The result pointer is actually equivalent to (on a 32-bit machine):
> 
>    (i32*)((i32)%A + Idx*4)

I guess that'll work, though it makes working with multidimensional arrays
trickier. However, this kind of thing may be unavoidable in the case of
multidimensional arrays with variable extents anyway, since LLVM's type
system doesn't represent that directly.

On a related note, I'm surprised there's no sign-extend SCEV. Is that
intentional or is it just not done yet?

Dan



More information about the llvm-dev mailing list