A question about integer promotion in GCC
Jie Zhang
zhangjie@magima.com.cn
Thu Sep 2 07:56:00 GMT 2004
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
More information about the Gcc
mailing list