public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Dhananjay R. Deshpande" <dhananjayd@kpit.com>
To: <gcc@gcc.gnu.org>
Subject: FW: H8300 optimization
Date: Thu, 25 Jul 2002 10:18:00 -0000	[thread overview]
Message-ID: <69595093233BB547BB70CF5E492B63F2531601@sohm.kpit.com> (raw)



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

                 reply	other threads:[~2002-07-25 11:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=69595093233BB547BB70CF5E492B63F2531601@sohm.kpit.com \
    --to=dhananjayd@kpit.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).