Path: utzoo!telly!ddsw1!mcdchg!rutgers!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!natinst!jclyde!bigtex!james
From: james@bigtex.cactus.org (James Van Artsdalen)
Newsgroups: gnu.gcc.bug
Subject: Re: GCC Version 1.31, '-fstrength-reduce' generates bad assembly
Message-ID: <11049@bigtex.cactus.org>
Date: 27 Nov 88 02:28:59 GMT
References: <8811260051.aa00576@gamma.eecs.nwu.edu>
Reply-To: james@bigtex.cactus.org (James Van Artsdalen)
Distribution: gnu
Organization: Institute of Applied Cosmology, Austin TX
Lines: 81

> 	Lawrence G. Mayka

In <8811260051.aa00576@gamma.eecs.nwu.edu>, Lawrence G. Mayka
(lmayk!lgm@ODDJOB.UCHICAGO.EDU) submitted a bug report about
-fstrength-reduce.  I tried the example on my SysVr3 gcc 1.31
and did not see the failure mode.  But I did see some strange,
sub-optimal code:

This:
---
struct	S {				/* structure is 14 bytes long */
	int	dummy1;
	short	dummy2;
	char	*field1;
	char	*field2;
};

extern	void	g();

void
f( nels, arr )
int	nels;
struct	S	*arr;
{
	int	i;

	for ( i = 0; i < nels; ++i ) {
		if ( arr[ i ].field1 )
			g( arr[ i ].field1 );
		if ( arr[ i ].field2 )
			g( arr[ i ].field2 );
	}
}
---
gives (via gcc -O -fstrength-reduce -S) this:
---
	.file	"strength1.c"
.text
	.align 4
.globl f
f:
	pushl %ebp
	movl %esp,%ebp
	subl $4,%esp			; we don't need this temp. space
	pushl %ebx
	pushl %esi
	pushl %edi
	xorl %ebx,%ebx			; i
	cmpl 8(%ebp),%ebx		; cmp  nels ,i
	jge .L8
	xorl %edi,%edi			; expected nifty array-index follower
.L7:
	movl 12(%ebp),%esi		; arr
	cmpl $0,8(%edi,%esi)		; why not copy this to ax for push?
	je .L5
	pushl 8(%edi,%esi)
	call g
	leal 4(%esp),%esp
.L5:
	movl %edi,-4(%ebp)		; huh?  -4(%ebp) is never read!
	movl 12(%ebp),%esi		; arr
	cmpl $0,12(%edi,%esi)
	je .L4
	pushl 12(%edi,%esi)
	call g
	leal 4(%esp),%esp
.L4:
	leal 16(%edi),%edi		; "add" is slightly faster than lea.
	incl %ebx			; i
	cmpl 8(%ebp),%ebx		; cmp nels, i
	jl .L7
.L8:
	leal -16(%ebp),%esp
	popl %edi
	popl %esi
	popl %ebx
	leave
	ret
-- 
James R. Van Artsdalen      james@bigtex.cactus.org      "Live Free or Die"
Home: 512-346-2444 Work: 338-8789       9505 Arboretum Blvd Austin TX 78759