loop strength reduction (was Another silly question)

Chris Torek chris at mimsy.UUCP
Tue May 23 10:05:39 AEST 1989


In article <1677 at auspex.auspex.com> guy at 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 at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list