Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (no subject)



>>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.
>
>Ian

Thanks for the quick and helpful response!

I wanted to mention it and then forgot, but yes, those variables are of external scope, as they are instance variables of an objc object. They are thus members of a struct, which is passed by ref to the function (as objc objects are pointers to struct). So yes, this is probably the problem. I never thought of it in this particular configuration... Is the fix to use a local variable instead? Something like:

double *p1=dsdrate;
double *p2=dsdr;
for (i=0;i<countSpecies;i++)
	p1[i]=p2[i];


Just in case, here is the assembly I should have added in the initial post (line 0x264d8 is not part of the loop per se; the loop is at the very beginning of the function; this is the assembly just for the loop):

0x264d0	lwz      r2,100(r3)	3:1
0x264d4	li       r6,0	1:1	
0x264d8	mr       r12,r5	1:1	
0x264dc	cmplw    r6,r2	1:1	
0x264e0	bge      $+36 <-[BCKCalculatorGeneric getdsdratedt:atTime:values:] + 52>	1:1	
0x264e4	 slwi     r0,r6,3	1:1
0x264e8	 lwz      r5,124(r3)	3:1	!Invariant load	
0x264ec	 addi     r6,r6,1	1:1
0x264f0	 lfdx     f1,r8,r0	4:1	
0x264f4	 stfdx    f1,r5,r0	3:3	
0x264f8	 lwz      r4,100(r3)	3:1	!Invariant load
0x264fc	 cmplw    r6,r4	1:1
0x26500	 blt      $-28 <-[BCKCalculatorGeneric getdsdratedt:atTime:values:] + 20>	1:1		Loop end[1]

The assembly for the line INSIDE the loop is:
0x264e4	 slwi     r0,r6,3	1:1
0x264e8	 lwz      r5,124(r3)	3:1	
0x264f0	 lfdx     f1,r8,r0	4:1
0x264f4	 stfdx    f1,r5,r0	3:3

thanks!

-- 
Charles Parnot
email@hidden

Help science go fast forward:
http://cmgm.stanford.edu/~cparnot/xgrid-stanford/

Room  B157 in Beckman Center
279, Campus Drive
Stanford University
Stanford, CA 94305 (USA)

Tel +1 650 725 7754
Fax +1 650 725 8021
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden

This email sent to email@hidden

References: 
 >(no subject) (From: Charles PARNOT <email@hidden>)
 >Re: (no subject) (From: Ian Ollmann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.