Number of Bytes a GetElementPtr .

Hi,

I have the value of a getelementptr instruction. How can i find how many bytes it is accessing from the base address. I need this to call the alias method.

Thanks,
Rohith.

hi,

You could get it from the ScalarEvolution analysis(target data must available):
c code:
int f(int a[][4], int i, int j) {
return a[i][j];
}
llvm ir:
define i32 @f([4 x i32]* nocapture %a, i32 %i, i32 %j) nounwind readonly {
entry:
%0 = sext i32 %i to i64 ; [#uses=1]
%1 = sext i32 %j to i64 ; [#uses=1]
%2 = getelementptr inbounds [4 x i32]* %a, i64 %0, i64 %1 ; <i32*> [#uses=1]
%3 = load i32* %2, align 4 ; [#uses=1]
ret i32 %3
}

SCEV expression of %2:
%2 = getelementptr inbounds [4 x i32]* %a, i64 %0, i64 %1 ; <i32*> [#uses=1]
→ ((4 * (sext i32 %j to i64)) + (16 * (sext i32 %i to i64)) + %a)

–best regards
ether

Hi Rohith,

   I have the value of a getelementptr instruction. How can i find how
many bytes it is accessing from the base address. I need this to call
the alias method.

you can find code doing this in lots of places. For example, take a
look at lines 205-220 in lib/Analysis/ConstantFolding.cpp, starting
     // Otherwise, add any offset that our operands provide.

Ciao,

Duncan.