[LLVMdev] getelementptr and SCEVs

Dan Gohman djg at cray.com
Fri Feb 23 08:20:21 PST 2007


I'm experimenting a bit with the SCEV code and one of the problems I'm
facing is that there's no way to represent a getelementptr operation as a
SCEV. The obvious way to do this in the existing SCEV framework is to add
a new SCEV subclass. I started doing that, but then I decided that it would
be nice to be able to split multiple-index getelementptrs into separate
SCEV objects that each cover a single index, so that it would be easy to do
things like recognize common prefixes. That turns out to be tricky because
the first index doesn't behave like the others.

Given an instruction like this (abbreviated syntax..):

x = getelementptr Z, a, b, c, d

the rewritten form looks (effectively) like this:

m = getelementptr Z, a
n = getelementptr m, 0, b
o = getelementptr n, 0, c
x = getelementptr o, 0, d

and the first index is clearly special. It's not possible to represent each
of these as uniform two-operand operations without some additional way to
tell which one was a "first" index.

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.

Dan



More information about the llvm-dev mailing list