public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hongtao Liu <crazylht@gmail.com>
To: Jeff Law <jeffreyalaw@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] RTL: Bugfix for wrong code with v16hi compare & mask
Date: Mon, 27 Mar 2023 09:36:44 +0800	[thread overview]
Message-ID: <CAMZc-bwPUd1yM=MqfHQnw478XqOkX2eycvmdWKou_mgR+GMM1A@mail.gmail.com> (raw)
In-Reply-To: <9aa74d50-a9db-7747-524e-9da839366433@gmail.com>

On Sun, Mar 26, 2023 at 3:01 AM Jeff Law via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
>
>
> On 3/24/23 08:11, pan2.li--- via Gcc-patches wrote:
> > From: Pan Li <pan2.li@intel.com>
> >
> > Fix the bug of the incorrect code generation for the
> > below code sample.
> >
> > typedef unsigned short __attribute__((__vector_size__ (32))) V;
> > typedef unsigned short u16;
> >
> > void
> > foo (V m, u16 *ret)
> > {
> >    V v = 6 > ((V) { 2049, 8 } & m);
> >    *ret = v[0]; // + a + b + c + d;
> > }
> >
> > Before this patch.
> > addi    sp,sp,-64
> > ld      a5,0(a0)
> > li      a4,528384
> > addi    a4,a4,-2047
> > and     a5,a5,a4
> > // slli    a5,a5,48 <- eliminated by mistake
> > // srli    a5,a5,48 <- eliminated by mistake
> > sltiu   a5,a5,6
> > negw    a5,a5
> > sh      a5,0(a1)
> >
> > After this patch.
> > addi    sp,sp,-64
> > ld      a5,0(a0)
> > li      a4,528384
> > addi    a4,a4,-2047
> > and     a5,a5,a4
> > slli    a5,a5,48
> > srli    a5,a5,48
> > sltiu   a5,a5,6
> > negw    a5,a5
> > sh      a5,0(a1)
> >
> > The simplify_comparation for the AND operation will
> > try to simplify below RTL code from:
> > (and:DI (subreg:DI (reg:HI 154) 0) (const_int 0x801))
> > to:
> > (subreg:DI (and (reg:HI 154) (const_int 0x801)) 0)
> These look equivalent to me -- assuming they're used as rvalues.
They're equivalent only when WORD_REGISTER_OPERATIONS, orelse the
upper bits of latter is UD, but the former is 0.

 (and (reg:HI 154) (const_int 0x801)) is simplified to (reg:HI 154)
since nonzero_bits (reg:154, HImode) is exactly same as 0x801.

These two optimizations are fine on their own, but if they are put
together, there are problems. The first optimization relies on the
WORD_REGISTER_OPERATIONS, but the second optimize the operation off
which make upper bits of (subreg:DI (reg:HI 154) 0) UD, but originally
it should be 0 after AND (const_int 0x801).
>
>
> >
> > If reg:HI 154 is 0x801 and reg:DI 154 is 0x80801, the RTL will
> > be simplified continuely to:
> That statement has no meaning.  Each pseudo has one and only one native
> mode and you can only refer to it in that mode.  ie reg:HI 154.  reg:DI
> 154 has no meaning.  You might say that (subreg:DI (reg:HI 154) 0) has
> the value 0x80801, but that's OK.  The subreg says those bits outside
> HImode simply don't matter -- you can not depend on them having any
> particular value.
>
> > (subreg:DI (reg:HI 154) 0)
> I think that's equivalent to (subreg:DI (and:HI (reg:HI 154) (const_int
> 0x801)) 0) when used as an rvalue.
>
> I suspect your problem is elsewhere.
>
> jeff
>


-- 
BR,
Hongtao

  reply	other threads:[~2023-03-27  1:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 14:11 pan2.li
2023-03-25 12:14 ` [PATCH v2] RISCV: " pan2.li
2023-03-25 19:00 ` [PATCH] RTL: " Jeff Law
2023-03-27  1:36   ` Hongtao Liu [this message]
2023-04-03  4:51     ` Jeff Law

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='CAMZc-bwPUd1yM=MqfHQnw478XqOkX2eycvmdWKou_mgR+GMM1A@mail.gmail.com' \
    --to=crazylht@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    /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).