public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "olegendo at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/53987] [SH] Unnecessary zero-extensions
Date: Thu, 15 Jan 2015 01:37:00 -0000	[thread overview]
Message-ID: <bug-53987-4-VOsspQQBRp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-53987-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53987

--- Comment #9 from Oleg Endo <olegendo at gcc dot gnu.org> ---
Another related issue is this example function:

unsigned char h (unsigned char a, int b)
{
  return (unsigned char)(a + b);
}

compiling with -O2 -mrenesas (which allows undefined high bits in the return
value):
        extu.b  r4,r4    << not needed
        mov     r5,r0
        rts
        add     r4,r0

It seems that the fwprop1 pass causes this.
The initial RTL for this looks like this:

(insn 2 5 3 2 (set (reg/v:SI 165 [ a ])
        (zero_extend:SI (reg:QI 4 r4 [ a ]))) sh_tmp.cpp:1550 -1
     (nil))
(insn 3 2 4 2 (set (reg/v:SI 166 [ b ])
        (reg:SI 5 r5 [ b ])) sh_tmp.cpp:1550 -1
     (nil))
(note 4 3 7 2 NOTE_INSN_FUNCTION_BEG)
(insn 7 4 8 2 (set (reg:QI 168)
        (subreg:QI (reg/v:SI 166 [ b ]) 0)) sh_tmp.cpp:1551 -1
     (nil))
(insn 8 7 9 2 (set (reg:SI 169)
        (plus:SI (reg/v:SI 165 [ a ])
            (subreg:SI (reg:QI 168) 0))) sh_tmp.cpp:1551 -1
     (nil))
(insn 9 8 13 2 (set (reg:QI 164 [ <retval> ])
        (subreg:QI (reg:SI 169) 0)) sh_tmp.cpp:1551 -1
     (nil))
(insn 13 9 14 2 (set (reg/i:QI 0 r0)
        (reg:QI 164 [ <retval> ])) sh_tmp.cpp:1552 -1
     (nil))
(insn 14 13 0 2 (use (reg/i:QI 0 r0)) sh_tmp.cpp:1552 -1
     (nil))


Notice that the plus op is expanded as a subreg:SI (reg:QI) and the result is
then taken as a subreg:QI.  This should be OK with the addsi3 pattern. 
However, fwprop1 then propagates the hardregs and eliminates the subregs:

(note 5 0 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(insn 2 5 3 2 (set (reg/v:SI 165 [ a ])
        (zero_extend:SI (reg:QI 4 r4 [ a ]))) sh_tmp.cpp:1550 218
{*zero_extendqisi2_compact}
     (expr_list:REG_DEAD (reg:QI 4 r4 [ a ])
        (nil)))
(insn 3 2 4 2 (set (reg/v:SI 166 [ b ])
        (reg:SI 5 r5 [ b ])) sh_tmp.cpp:1550 252 {movsi_ie}
     (expr_list:REG_DEAD (reg:SI 5 r5 [ b ])
        (nil)))
(note 4 3 8 2 NOTE_INSN_FUNCTION_BEG)
(insn 8 4 13 2 (set (reg:SI 169)
        (plus:SI (reg/v:SI 165 [ a ])
            (reg/v:SI 166 [ b ]))) sh_tmp.cpp:1551 63 {*addsi3_compact}
     (expr_list:REG_DEAD (reg:QI 168 [ b ])
        (expr_list:REG_DEAD (reg/v:SI 165 [ a ])
            (nil))))
(insn 13 8 14 2 (set (reg/i:QI 0 r0)
        (subreg:QI (reg:SI 169) 0)) sh_tmp.cpp:1552 270 {*movqi}
     (expr_list:REG_DEAD (reg:SI 169)
        (nil)))
(insn 14 13 0 2 (use (reg/i:QI 0 r0)) sh_tmp.cpp:1552 -1
     (nil))

After that, everything is pretty much set and the zero extension will not be
eliminated anymore.


  parent reply	other threads:[~2015-01-15  1:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-16 23:50 [Bug target/53987] New: [SH] Unnecessary zero-extension before cmp/eq olegendo at gcc dot gnu.org
2012-08-31 18:14 ` [Bug target/53987] " olegendo at gcc dot gnu.org
2013-10-29 21:58 ` olegendo at gcc dot gnu.org
2013-12-16 19:07 ` olegendo at gcc dot gnu.org
2014-12-17 21:09 ` olegendo at gcc dot gnu.org
2014-12-21 16:54 ` [Bug target/53987] [SH] Unnecessary zero-extensions olegendo at gcc dot gnu.org
2014-12-22 22:27 ` olegendo at gcc dot gnu.org
2014-12-25  1:11 ` olegendo at gcc dot gnu.org
2014-12-30 17:26 ` olegendo at gcc dot gnu.org
2015-01-15  1:37 ` olegendo at gcc dot gnu.org [this message]
2015-01-24 13:06 ` olegendo at gcc dot gnu.org
2015-01-27 23:08 ` olegendo at gcc dot gnu.org
2015-08-01  9:57 ` olegendo at gcc dot gnu.org
2015-09-09 12:15 ` olegendo at gcc dot gnu.org

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=bug-53987-4-VOsspQQBRp@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).