[LLVMdev] Number of Bytes a GetElementPtr .

ether zhhb
2010-04-20T03:51:50Z

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                         ; <i64> [#uses=1]
  %1 = sext i32 %j to i64                         ; <i64> [#uses=1]
  %2 = getelementptr inbounds [4 x i32]* %a, i64 %0, i64 %1 ; <i32*>
[#uses=1]
  %3 = load i32* %2, align 4                      ; <i32> [#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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20100420/d1ae4ab0/attachment.html>