Fusing GEPIs

Hi,

Is there any standard pass or something that can fuse chained GEPIs?

I.e. turning
  b = getelementptr a, 10, 1
  c = getelementptr b, 0, 3
  d = getelementptr c, 0, 5
into:
  d = getelementptr a, 10, 1, 3, 5

In our case this would greatly simplify some analysis passes, at the moment we have to trace back a gepi-chain and extract all the indices manually (the original object is available through the getUnderlyingObject method, so that doesn't pose any problems).

Kind regards,
Mattias

Is there any standard pass or something that can fuse chained GEPIs?

I.e. turning
  b = getelementptr a, 10, 1
  c = getelementptr b, 0, 3
  d = getelementptr c, 0, 5
into:
  d = getelementptr a, 10, 1, 3, 5

I think instcombine does this.

Ciao,

Duncan.

An alternative to manually analyzing GEPs is to use the ScalarEvolution
pass. In TOT, ScalarEvolution will automatically analyze chains of GEPs
and other things, and present them in a normalized form. One of
the intentions of this is to support clients that want to understand
memory access patterns.

Given a LoadInst or StoreInst, ask ScalarEvolution for the SCEV expression
for the address operand. Among other things, that indicates which loops
affect the address' value and what the strides are from each loop.

Dan