public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Optimization disappears in the easier case
@ 1998-04-24 16:23 Iain McClatchie
  0 siblings, 0 replies; only message in thread
From: Iain McClatchie @ 1998-04-24 16:23 UTC (permalink / raw)
  To: egcs

I've furthur reduced the problem, and found a somewhat surprising
result.

In the following test case, I have two loops, which I've juxtaposed
with the resulting code from egcs-1.0.2.  The second is inside a
templatized function, and shows a nice tail-branch optimization.  The
first is inside a non-templatized function, and does NOT have the
optimization.  Aside from the context, the two functions are
identical.

Can someone please take a look?  This really looks like a pretty
simple bug.

-Iain McClatchie

class ent {
public:
};

template <class base>
class list : public base {
public:
  const char    *str;
  list          *next;
};

static inline
int
match( list<ent> *listp, list<ent> &key )
{
  return( listp->str == key.str );
}

ent *                                           lookup1:                 
lookup1( list<ent> *listp, list<ent> &key )	        pushl %ebp       
{						        movl %esp,%ebp   
  for( ; listp; listp = listp->next ) {		        movl 8(%ebp),%edx
    if( match( listp, key ))			        movl 12(%ebp),%ec
      return listp;				        .align 4         
  }						.L4:                     
  return listp;					        testl %edx,%edx  
}						        je .L5           
						        movl 4(%ecx),%eax
						        cmpl %eax,4(%edx)
						        je .L5           
						        movl 8(%edx),%edx
						        jmp .L4          
						        .align 4         
						.L5:                     
						        movl %edx,%eax   
						        movl %ebp,%esp   
						        popl %ebp        
						        ret              

template <class base>				lookup2:                  
base *						        pushl %ebp        
lookup2( list<base> *listp, list<base> &key )	        movl %esp,%ebp    
{						        movl 8(%ebp),%edx 
  for( ; listp; listp = listp->next ) {		        testl %edx,%edx   
    if( match( listp, key ))			        je .L17           
      return listp;				        movl 12(%ebp),%eax
  }						        movl 4(%eax),%eax 
  return listp;					        .align 4          
}						.L19:                     
						        cmpl %eax,4(%edx) 
template class list<ent>;			        je .L17           
						        movl 8(%edx),%edx 
ent *						        testl %edx,%edx   
baz()						        jne .L19          
{						.L17:                     
  list<ent>    key;				        movl %edx,%eax    
  list<ent>   *l = 0;				        movl %ebp,%esp    
  return lookup2( l, key );			        popl %ebp         
}						        ret

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-04-24 16:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-24 16:23 Optimization disappears in the easier case Iain McClatchie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).