public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gmail.com>
To: Daniil Frolov <exactlywb@ispras.ru>
Cc: gcc@gcc.gnu.org
Subject: Re: Question on GIMPLE shifts
Date: Wed, 1 Nov 2023 09:00:04 -0700	[thread overview]
Message-ID: <CA+=Sn1mi7ecRGMZsqTR9SRuDwtvBJ-zGNouAT78BQL_Eb7X+ww@mail.gmail.com> (raw)
In-Reply-To: <95455bb364b144ec591aa5a61347bf62@ispras.ru>

On Wed, Nov 1, 2023 at 3:56 AM Daniil Frolov <exactlywb@ispras.ru> wrote:
>
> Hi!
>
> When investigating bit shifts I got an incomprehensible moment with
> the following example:
>
> int f(int x, int k)
> {
>      int tmp = x >> k;
>      return (tmp & 1) << 10;
> }
>
> If we would like to take a look into GIMPLE then we'll get:
>
> int f (int x, int k)
> {
>    int tmp;
>    int D.2746;
>    int _1;
>    int _5;
>
>    <bb 2> :
>    tmp_4 = x_2(D) >> k_3(D);
>    _1 = tmp_4 << 10;
>    _5 = _1 & 1024;
>
>    <bb 3> :
> <L0>:
>    return _5;
>
> }
>
> Is the expression '_1 = tmp_4 << 10' considered legal in GIMPLE?  Given
> the
> semantics of C bit shifts, this statement could modify the sign bit,
> potentially leading to overflow.

Except it was not undefined in C90.

Thanks,
Andrew

>
> ---
> With best regards,
> Daniil

  reply	other threads:[~2023-11-01 16:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-01  9:52 Daniil Frolov
2023-11-01 16:00 ` Andrew Pinski [this message]
2023-11-02  8:00   ` Richard Biener

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='CA+=Sn1mi7ecRGMZsqTR9SRuDwtvBJ-zGNouAT78BQL_Eb7X+ww@mail.gmail.com' \
    --to=pinskia@gmail.com \
    --cc=exactlywb@ispras.ru \
    --cc=gcc@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).