From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30428 invoked by alias); 30 Apr 2003 06:16:02 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 30395 invoked by uid 71); 30 Apr 2003 06:16:01 -0000 Resent-Date: 30 Apr 2003 06:16:01 -0000 Resent-Message-ID: <20030430061601.30393.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, eddie.dong@intel.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, fleming.feng@intel.com Received: (qmail 29295 invoked by uid 48); 30 Apr 2003 06:12:12 -0000 Message-Id: <20030430061212.29294.qmail@sources.redhat.com> Date: Wed, 30 Apr 2003 06:16:00 -0000 From: fleming.feng@intel.com Reply-To: fleming.feng@intel.com To: gcc-gnats@gcc.gnu.org Cc: eddie.dong@intel.com X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify: eddie.dong@intel.com Subject: optimization/10562: Code segment optimization incorrectly disappeared with -O2 option X-SW-Source: 2003-04/txt/msg01433.txt.bz2 List-Id: >Number: 10562 >Category: optimization >Synopsis: Code segment optimization incorrectly disappeared with -O2 option >Confidential: no >Severity: critical >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Wed Apr 30 06:16:01 UTC 2003 >Closed-Date: >Last-Modified: >Originator: fleming.feng@intel.com >Release: gcc-3.2 20020903 >Organization: >Environment: Red Hat Linux 8.0 3.2-7 >Description: When I compile the following code with a header file and a C file like following: test.h #define cpu_online_map 1 static inline unsigned int generic_hweight32(unsigned int w) { unsigned int res = (w & 0x55555555) + ((w >> 1) & 0x55555555); res = (res & 0x33333333) + ((res >> 2) & 0x33333333); res = (res & 0x0F0F0F0F) + ((res >> 4) & 0x0F0F0F0F); res = (res & 0x00FF00FF) + ((res >> 8) & 0x00FF00FF); return (res & 0x0000FFFF) + ((res>>16) & 0x0000FFFFF); } #define hweight32(x) generic_hweight32(x) static inline unsigned int num_online_cpus(void) { return hweight32(cpu_online_map); } test.c #include #include "test.h" int main(int argc, char* argv[]) { int i; for(i = 0; i < num_online_cpus(); i++){ printf("gcc compiled correctly!\n"); } return 0; } The code in the "for" loop should at least executed one time! Because it equals to: for(i = 0; i < 1; i ++){ .... } but if it is compiled with -O2 option the code segment in "for" loop will not be executed. Using objdump to disassembly the output file, it can be found the code segment disappeared. If only use -O option, the result is correct. In fact the code in header file comes from linux kernel 2.4.19. And the bug is found during compile a kernel mode driver. This also happens on arm-linux-gcc version 3.2.1 which is a cross compile tool chain for ARM platform. >How-To-Repeat: Just compile the code in description with -O2 option and execute the output file. >Fix: >Release-Note: >Audit-Trail: >Unformatted: