From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22848 invoked by alias); 2 Sep 2004 07:56:08 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 22823 invoked from network); 2 Sep 2004 07:56:07 -0000 Received: from unknown (HELO nemail-g1.xinnet.com) (210.51.172.174) by sourceware.org with SMTP; 2 Sep 2004 07:56:07 -0000 Received: (qmail 91259 invoked from network); 2 Sep 2004 08:03:31 -0000 Received: from unknown (HELO ?10.0.0.44?) (61.152.127.250) by 0 with SMTP; 2 Sep 2004 08:03:31 -0000 Message-ID: <4136D20A.7010609@magima.com.cn> Date: Thu, 02 Sep 2004 07:56:00 -0000 From: Jie Zhang User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) MIME-Version: 1.0 To: gcc@gcc.gnu.org Subject: A question about integer promotion in GCC Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2004-09/txt/msg00096.txt.bz2 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