On Oct 26, 2004, at 11:47 AM, Charles PARNOT wrote:
Sorry this is probably a very basic question, as I don't have a strong
knowledge in the field, but here is my question.
I use Shark to optimize some of my code (so far, ~3-4 fold increase,
after ~ half a dozen hot spots were fixed). However, I found in many
places the comment 'Invariant load', typically when looping over an
array and using the loop variable as the index (this particular code
is not worth any optimization, it is just the simplest example I could
find in my code):
/* int i ; double *dsdrate,*dsdr */
for (i=0;i<countSpecies;i++) /* Invariant load, Early exit */
dsdrate[i]=dsdr[i]; /* Invariant load, Unroll, Unaligned loop start
*/
So what exactly is causing these 'Invariant load' warnings from Shark?
It seems it disappears when I increment a pointer inside the loop
instead, like so (I did not test that particular code in Shark,
though):
double *p1=dsdrate;
double *p2=dsdr;
for (i=0;i<countSpecies;i++) {
*p1=*p2;
p1++;
p2++;
}
There are maybe a couple of places where I could do some optimization
on those 'Invariant load' warnings. Thanks for your input!
This frequently happens when the array in question is of global or
external scope. The compiler might be reloading the pointer to the
array each time through the loop, just in case someone else changed it,
perhaps in another thread.
We'd have to see the disassembly for the loop showing what was loaded
and perhaps also the exact source showing how dsdrate and dsdr are
declared to be sure.