public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* FW: H8300 optimization
@ 2002-07-25 10:18 Dhananjay R. Deshpande
  0 siblings, 0 replies; only message in thread
From: Dhananjay R. Deshpande @ 2002-07-25 10:18 UTC (permalink / raw)
  To: gcc



-----Original Message-----
From: Dhananjay R. Deshpande 
Sent: Thursday, July 25, 2002 4:47 PM
To: 'gcc-bugs@gcc.gnu.org'
Subject: H8300 optimization


Hi,

I have a simple function which returns max of two unsigned integers.

unsigned int maxu(unsigned int a, unsigned int b)
{
  return ( a > b ? a : b );
}

Compiling it with h8300-hms-gcc -S -O2 -fomit-frame-pointer gives -
 
        .section .text
        .align 1
        .global _maxu
_maxu:
        mov.w   r0,r2
        mov.w   r1,r0
        cmp.w   r2,r1
        bhs     .L2
        mov.w   r2,r0
.L2:
        rts
        .end
        .ident
"GCC: (GNU) 3.1"

Here use of r2 as scratch register is not required. One could write 

		cmp.w     r1,r0    
            bhs       .L2
            mov.w     r1,r0 
.L2: 

This could save 2 instructions. Is it possible to generate this sequence
from compiler? 

I tried to understand from RTL dump how r2 comes into picture. It looks
like global reg alloc allocates r0 for b and r2 for a and this is causing 
use of extra register and 2 extra instructions.

Regards,
Dhananjay

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

only message in thread, other threads:[~2002-07-25 11:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-25 10:18 FW: H8300 optimization Dhananjay R. Deshpande

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).