About Scalar Evolution Pass and SCEVAddRecExpr

I wonder how many of you are familiar with scalar evolution pass. I met a
problem regarding to the SCEVAddRecExpr. Say for the code:
const int N = 100;
int a[N];
for(int i=0;i<N;i++) a[i] = 0;
For the access of a[i], the pass will transform this a[i] to a
SCEVAddRecExpr <@a, +, sizeof(int)><BB_Name>, which means the access of the
array `a' starts from the address `a' and has an access stride of
However, when this code is slightly modified:

const int N=100;
int a[N];
int i;
for(i=0;i<N-1; i++) {}
a[i] = 0;

So the loop is empty and there's an access of `a[i]' (actually a[99] in this
case), this a[i] will still be transformed into the same SCEVAddRecExpr as
above. This does not really seem to make sense to me because the access
pattern is not really so at all. Is is a small bug in this tool? Thank you!


You may try function "getSCEVAtScope" of the ScalarEvolution analysis:

/// getSCEVAtScope - Return a SCEV expression for the specified value
/// at the specified scope in the program. The L value specifies a loop
/// nest to evaluate the expression at, where null is the top-level or a
/// specified loop is immediately inside of the loop.
/// This method can be used to compute the exit value for a variable defined
/// in a loop by querying what the value will hold in the parent loop.
/// In the case that a relevant loop exit value cannot be computed, the
/// original value V is returned.

best regards

Hi, thank you for your suggestion. It works well now!

Hongbin Zheng wrote: