[LLVMdev] ScalarEvolution: Suboptimal handling of globals
Vaivaswatha N
vaivaswatha at yahoo.co.in
Thu Nov 27 23:48:48 PST 2014
Hi,
For the program below, where "incr" and "Arr" are globals
=================================
int incr;
float Arr[1000];
int foo ()
{
float x = 0;
int newInc = incr+1;
for (int i = 0; i < 1000; i++) {
for (int j = 0; j < 1000; j += incr) {
x += (Arr[i] + Arr[j]);
}
}
return x;
}
=================================
The SCEV expression computed for the variable "j" is %j.0 = phi i32 [ 0, %for.body ], [ %add8, %for.inc ]
--> %j.0 Exits: <<Unknown>>As is evident, this isn't a useful computation.
Whereas if I use the variable newInc to be the increment for "j", i.e., "j += newInc" in the inner loop, the computed SCEV is %j.0 = phi i32 [ 0, %for.body ], [ %add8, %for.inc ]
--> {0,+,(1 + %0)}<nsw><%for.cond1>
where %0 here is a LoadInst for "incr". In this situation, the analysis is working as expected to compute the add-recurrence for "j".
I would've expected a similar computation for the first case too, something like {0,+,%0}<nsw><%for.cond1>
Where %0 would be the LoadInst for "incr".
Is this a bug or is there something more involved that causes the deficiency?
Thanks,- Vaivaswatha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141128/c59536db/attachment.html>
More information about the llvm-dev
mailing list