public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: Richard Sandiford <richard.sandiford@arm.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Adjust LSHIFT_EXPR handling of multiple_of_p
Date: Fri, 4 Feb 2022 11:20:55 +0100 (CET)	[thread overview]
Message-ID: <52p4s856-353p-4on4-n588-34355829074@fhfr.qr> (raw)
In-Reply-To: <mpt35kzaqq6.fsf@arm.com>

On Fri, 4 Feb 2022, Richard Sandiford wrote:

> Richard Biener <rguenther@suse.de> writes:
> > This removes the odd check of size_type_node when handling left-shifts
> > as multiplications of 1 << N and instead uses the type as specified.
> > It also moves left-shift handling next to multiplications where it
> > semantically belongs.
> >
> > Boostrap and regtest pending on x86_64-unknown-linux-gnu.
> >
> > OK?  (I failed to short-cut the wide_int_to_tree for a
> > poly_int_cst_p bottom)
> >
> > Thanks,
> > Richard.
> >
> > 2022-01-24  Richard Biener  <rguenther@suse.de>
> >
> > 	* fold-const.cc (multiple_of_p): Re-write and move LSHIFT_EXPR
> > 	handling.
> > ---
> >  gcc/fold-const.cc | 33 ++++++++++++++++-----------------
> >  1 file changed, 16 insertions(+), 17 deletions(-)
> >
> > diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
> > index b155611578d..a0a4913c45e 100644
> > --- a/gcc/fold-const.cc
> > +++ b/gcc/fold-const.cc
> > @@ -14068,7 +14068,7 @@ int
> >  multiple_of_p (tree type, const_tree top, const_tree bottom)
> >  {
> >    gimple *stmt;
> > -  tree t1, op1, op2;
> > +  tree op1, op2;
> >  
> >    if (operand_equal_p (top, bottom, 0))
> >      return 1;
> > @@ -14114,6 +14114,21 @@ multiple_of_p (tree type, const_tree top, const_tree bottom)
> >        return (multiple_of_p (type, TREE_OPERAND (top, 1), bottom)
> >  	      || multiple_of_p (type, TREE_OPERAND (top, 0), bottom));
> >  
> > +    case LSHIFT_EXPR:
> > +      /* Handle X << CST as X * (1 << CST) and only process the constant.  */
> > +      if (TREE_CODE (TREE_OPERAND (top, 1)) == INTEGER_CST)
> > +	{
> > +	  op1 = TREE_OPERAND (top, 1);
> > +	  if (wi::gtu_p (TYPE_PRECISION (type), wi::to_wide (op1)))
> > +	    {
> > +	      wide_int mul_op
> > +		= wi::one (TYPE_PRECISION (type)) << wi::to_wide (op1);
> > +	      return multiple_of_p (type,
> > +				    wide_int_to_tree (type, mul_op), bottom);
> > +	    }
> > +	}
> > +      return 0;
> > +
> 
> LGTM.  Sorry for the slow response.
> 
> I guess the condition could be written:
> 
>     if (wi::to_widest (op1) < TYPE_PRECISION (type))
> 
> which might be more readable, and also avoids accidentally reinterpreting
> a sign.

Good idea - I'll adjust, re-test and push.

Thanks,
Richard.

      reply	other threads:[~2022-02-04 10:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24 14:47 Richard Biener
2022-02-04 10:08 ` Richard Sandiford
2022-02-04 10:20   ` Richard Biener [this message]

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=52p4s856-353p-4on4-n588-34355829074@fhfr.qr \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.sandiford@arm.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).