public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bina2374 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/95632] Redundant zero extension
Date: Mon, 15 Jun 2020 09:49:16 +0000	[thread overview]
Message-ID: <bug-95632-4-XG1d4EIWAC@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-95632-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Mel Chen <bina2374 at gmail dot com> ---
(In reply to Jim Wilson from comment #1)
> We sign extend HImode constants as that is the natural thing to do to make
> arithmetic work.  This does mean that unsigned short logical operations need
> a zero extend after the operation which might otherwise be unnecessary. 
> This can't be handled at rtl generation time as we don't know if the
> constant will be used for arithmetic or logicals or signed or unsigned.  But
> maybe an optimization pass could go over the code and convert HImode
> constants to signed or unsigned as appropriate to reduce the number of
> sign/zero extend operations.  We have the ree pass that we might be able to
> extend to handle this.

Extend ree pass is a good way, but now it seems only scanning XXX_extend.
Because the zero_extend has been split to 2 shift instructions before ree pass,
do we need to keep zero_extend until ree pass? Or is there any other way to
know that the shift pair was a zero_extend?
> 
> Handling this in combine requires a 4->3 splitter which is something combine
> doesn't do.  We could work around that by not splitting constants before
> combine, but that would be a major change and probably not beneficial, as we
> wouldn't be able to easily optimize the high part of the constants anymore.

I agree. This way is a bit risky.
> 
> Another approach here might be to split the xor along with the constant.  If
> we generated something like
> 	srli	a0,a0,1
>         xori    a0,a0,1
> 	li	a5,-24576
> 	xor	a0,a0,a5
> then we can optimize away the following zero extend with a 3->2 splitter
> which combine already supports via find_split_point.  We can still optimize
> the high part of the constant. Since the immediates are sign extended, if
> the low part of the immediate has the sign bit set, we would have to invert
> the high part of the immediate to get the right result.  At least I think
> that works, I haven't double checked it yet.  This only works for or if the
> low part doesn't have the sign bit set.  And this only works for and if the
> low part does have the sign bit set.

I'm not sure how difficult it is to split 1 xor to 2 xor before combine pass,
but I have another proposal:

The following dump is combine dump:
Trying 8, 9, 10 -> 11:
    8: r79:SI=0xffffffffffffa000
    9: r78:SI=r79:SI+0x1
      REG_DEAD r79:SI
      REG_EQUAL 0xffffffffffffa001
   10: r77:SI=r72:SI^r78:SI
      REG_DEAD r78:SI
      REG_DEAD r72:SI
   11: r80:SI=zero_extend(r77:SI#0)
      REG_DEAD r77:SI
Failed to match this instruction:
(set (reg:SI 80)
    (xor:SI (reg:SI 72 [ _4 ])
        (const_int 40961 [0xa001])))

Is it possible to pretend that we have a pattern that can match xor (reg:SI
80), (reg: SI 72), 0xa001 in combine pass?
And then, if the constant part is too large to put in to the immediate part, it
can be split to 2 xor in split pass.

  parent reply	other threads:[~2020-06-15  9:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11  4:06 [Bug target/95632] New: " bina2374 at gmail dot com
2020-06-12  4:25 ` [Bug target/95632] " wilson at gcc dot gnu.org
2020-06-15  9:49 ` bina2374 at gmail dot com [this message]
2020-06-16  0:01 ` wilson at gcc dot gnu.org
2020-06-16  0:02 ` wilson at gcc dot gnu.org
2020-06-16  7:15 ` ubizjak at gmail dot com
2020-06-16  7:21 ` ubizjak at gmail dot com
2021-05-30 22:26 ` pinskia at gcc dot gnu.org
2022-12-27 23:31 ` cvs-commit at gcc dot gnu.org
2022-12-27 23:32 ` law 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-95632-4-XG1d4EIWAC@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).