This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FW: H8300 optimization



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]