public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* A question about integer promotion in GCC
@ 2004-09-02  7:56 Jie Zhang
  2004-09-02  8:09 ` Jie Zhang
  2004-09-02  8:19 ` Joseph S. Myers
  0 siblings, 2 replies; 10+ messages in thread
From: Jie Zhang @ 2004-09-02  7:56 UTC (permalink / raw)
  To: gcc

For this simple case:

   int
   foo (unsigned short x)
   {
     return (x << 8) | (x >> 8);
   }

its t03.original dump is:

   ;; Function foo (foo)
   ;; enabled by -tree-original


   {
     return (int)x << 8 | (int)(x >> 8);
   }

My question is why GCC treat two bitwise shift operators differently. 
C99 reads:

   (6.5.7.3) The integer promotions are performed on each of the
   operands. The type of the result is that of the promoted left
   operand. [snip]

According to this, shouldn't it be:

     return (int)x << 8 | (int)x >> 8;

Maybe it has no performance benefit. But it make the tree dump result 
conforming to the standard and improve the readability of the final 
assembly output when being compiled using -O2 option. How about your 
thoughts?


regards
-- 
Jie

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

end of thread, other threads:[~2004-09-06 11:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-02  7:56 A question about integer promotion in GCC Jie Zhang
2004-09-02  8:09 ` Jie Zhang
2004-09-02  8:19 ` Joseph S. Myers
2004-09-03  8:33   ` Jie Zhang
2004-09-06  8:01   ` Nathan Sidwell
2004-09-06  8:43     ` Joseph S. Myers
2004-09-06  8:52       ` Nathan Sidwell
2004-09-06  9:01         ` Joseph S. Myers
2004-09-06  9:54           ` Nathan Sidwell
2004-09-06 11:59             ` Joseph S. Myers

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