public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Xi Ruoyao <xry111@xry111.site>
To: Jeff Law <jeffreyalaw@gmail.com>, gcc-patches@gcc.gnu.org
Cc: Jakub Jelinek <jakub@redhat.com>,
	chenglulu <chenglulu@loongson.cn>,
	 i@xen0n.name, xuchenghua@loongson.cn, c@jia.je
Subject: Re: [PATCH] middle-end: Call negate_rtx instead of simplify_gen_unary expanding rotate shift [PR113033]
Date: Tue, 19 Dec 2023 00:48:46 +0800	[thread overview]
Message-ID: <d844abec473247365cf7f5d079984d74b6d20120.camel@xry111.site> (raw)
In-Reply-To: <a4f25faa-4168-4355-b1c4-ed90f3bff3cc@gmail.com>

On Mon, 2023-12-18 at 08:39 -0700, Jeff Law wrote:
> 
> 
> On 12/18/23 06:42, Xi Ruoyao wrote:
> > With simplify_gen_unary we end up with a not fully expanded RTX like
> > 
> >      (set (reg:SI 90) (and:SI (neg:SI (reg:SI 80)) (const_int 63)))
> > 
> > Then it will cause an ICE with unrecognizable insn.
> > 
> > gcc/ChangeLog:
> > 
> > 	PR middle-end/113033
> > 	* expmed.cc (expand_shift_1): When expanding rotate shift, call
> > 	negate_rtx instead of simplify_gen_unary (NEG, ...).

> The key difference being that using negate_rtx will go through the 
> expander which knows how to synthesize negation whereas 
> simplify_gen_unary will just generate a (neg ...) and assume it matches 
> something in the backend, right?

For PR113033 the key difference (to me) is negate_rtx emits an insn to
set a new pseudo reg to -x.  So the result will be

(set (reg:SI 81) (neg:SI (reg:SI 80)))

then

(and (reg:SI 81) (const_int 31))

instead of a consolidated

(and:SI (neg:SI (reg:SI IN)) (const_int 63))

AFAIK no backends have an instruction doing "negate an operand then and
bitwisely".

To me, technically the following operation

other_amount
  = simplify_gen_binary (AND, GET_MODE (op1), other_amount,
                         gen_int_mode (mask, GET_MODE (op1)));

should also be something negate_rtx too or we may still end up with an
ICE with backends incapable to match

(set (reg:SI XX) (and (reg:SI 81) (const_int 31)))

But fortunately most backends has an immediate and operation so it's
unlikely to blow up...

> If so, this patch is fine for the trunk.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-12-18 16:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-18 13:42 Xi Ruoyao
2023-12-18 15:39 ` Jeff Law
2023-12-18 16:48   ` Xi Ruoyao [this message]
2023-12-18 17:45     ` Jakub Jelinek
2023-12-18 20:01       ` Xi Ruoyao
2023-12-18 20:15         ` Jakub Jelinek
2023-12-18 20:18           ` Xi Ruoyao

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=d844abec473247365cf7f5d079984d74b6d20120.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=c@jia.je \
    --cc=chenglulu@loongson.cn \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=i@xen0n.name \
    --cc=jakub@redhat.com \
    --cc=jeffreyalaw@gmail.com \
    --cc=xuchenghua@loongson.cn \
    /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).