public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Question on GIMPLE shifts
@ 2023-11-01  9:52 Daniil Frolov
  2023-11-01 16:00 ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: Daniil Frolov @ 2023-11-01  9:52 UTC (permalink / raw)
  To: gcc

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.

---
With best regards,
Daniil

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-02  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-01  9:52 Question on GIMPLE shifts Daniil Frolov
2023-11-01 16:00 ` Andrew Pinski
2023-11-02  8:00   ` Richard Biener

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).