Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: loop strength reduction (was Another silly question) Message-ID: <17692@mimsy.UUCP> Date: 23 May 89 00:05:39 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <1677@auspex.auspex.com> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 50 In article <1677@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: > for (i = 0; i < LEN; i++) > a[i] = 0; >... on most architectures, this requires that the value in "i" be >multiplied by "sizeof a[0]" before being added to the address >represented by the address of "a[0]", and do a strength reduction on >that multiplication; you then find the induction variable not used, and >eliminate it, and by the time the smoke clears you have the loop in the >first example generating the same code as the loop in the second >example. (I don't know whether there are any compilers that do this or >not.) I fed this through gcc (1.35/vax) using -fstrength-reduce and it produced the following equivalent: movl $19,r1 addl3 $_a,$76,r0 L4: clrl (r0) subl2 $4,r0 decl r1 jgeq L4 ... (using `-mgnu' one gets a jsobgeq instead of decl+jgeq). I am surprised that, while it inverts the loop counter, it does not use the predecrement addressing mode---I rather expected movl $19,r1 moval _a+80,r0 # or movab; gcc uses movab elsewhere L4: clrl -(r0) jsobgeq r1,L4 Or, alternatively, post-increment: movl $19,r1 moval _a,r0 L4: clrl (r0)+ jsobgeq r1,L4 Or (better but less likely) quadword operations: movl $9,r1 moval _a,r0 L4: clrq (r0)+ jsobgeq r1,L4 -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris