loop strength reduction (was Another silly question)

Guy Harris guy at auspex.auspex.com
Wed May 24 04:01:06 AEST 1989


>>(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:

...


>(using `-mgnu' one gets a jsobgeq instead of decl+jgeq). ...

What, not a "sobjgeq"?  Perhaps they decided it was unpronounceable.... :-)

...

>...I am surprised that, while it inverts the loop counter, it does not
>use the predecrement addressing mode---I rather expected

...

>Or, alternatively, post-increment:

Oh well.  Silly me; I should have just tried "cc -S -O4" on the Sun-3
here if I wanted to see if any compilers would do the optimizations in
question; when I did so on the "for (i = 0; ...)" loop, I got:

	...
	moveq	#0,d7		# i = 0;
	movl	#_a,a0		# a0 = &a[0];
	moveq	#0,d1
	addl	d1,a0		# a0 += 0;	/* say WHAT? */
	jra	LY00000
LY00001:
	clrl	a0 at +		# *a0++ = 0;
	addql	#1,d7		# i++;
LY00000:
	moveq	#33,d1		# if (i < 33)
	cmpl	d1,d7
	jlt	LY00001		# keep looping

	...

which did use post-increment, but generated some superfluous goo (the
"a0 += 0" stuff).  It also didn't bother optimizing the loop test, and
nuking "i" entirely, which it can get away with given that "i" is only
used as an array index in the body of the loop and isn't used at all
after the loop terminates.



More information about the Comp.lang.c mailing list