From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21869 invoked by alias); 1 Jul 2005 10:29:46 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21850 invoked by uid 48); 1 Jul 2005 10:29:42 -0000 Date: Fri, 01 Jul 2005 10:29:00 -0000 From: "A dot Salwa at osmosys dot tv" To: gcc-bugs@gcc.gnu.org Message-ID: <20050701102939.22266.A.Salwa@osmosys.tv> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug tree-optimization/22266] New: bad code generation at -O1 (conditional expression and constants) X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg00038.txt.bz2 List-Id: The attached code is compiled OK at -O0 level, but at -O1 it produces bad results. The bug occurs somewhere in expression: ((a)==INT_MIN && (b)==-1)?(INT_MIN):((a)/(b)) where a and b are ints. a is not INT_MIN and b is not -1, so division shall be performed. But at -O1 INT_MIN is returned instead. gcc version 4.0.0 20050519 (Red Hat 4.0.0-8) Attached is full preprocessed source (*.i file) and a shell script that tries to detect which compilation flag causes the failure. It shows that the test passes when compiled with '-O1 -fno-tree-ccp'. tree-ccp_bug.c file (just for quick reading; I'll attach full *.i file in a few seconds anyway): #include #include #define i_div(a, b) (((a)==INT_MIN && (b)==-1)?(INT_MIN):((a)/(b))) // 2 macros just to make an assignment look a bit more complicated for compiler: #define i_low_set(a, b) \ ((a)&=(int)0xffff0000UL, (a)|=(int)(unsigned short)(b)) #define i_high_set(a, b) \ ((a)&=(int)0x0000ffffL, (a)|=((int)(short)(b))<<16) int main(int argv, char*argc) { int d1; int d2; int s1, s2; int b; i_high_set(d1, 0x344); i_low_set(d1, 0x4567); //d1 = 0x3444567; // this makes test pass i_high_set(d2, 0); i_low_set(d2, 0x3b9a); printf(" dividend >>: %ld\n", d1); printf(" divisor >>: %ld\n", d2); // just to check that the subexpression alone is computed correctly: b = (d1)==INT_MIN && (d2)==-1; s1 = d1/d2; s2 = i_div(d1, d2); printf(" results >>: %d, %ld, %ld\n", b, s1, s2); if(s1!=s2) printf(" FAILED\n"); } -- Summary: bad code generation at -O1 (conditional expression and constants) Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: A dot Salwa at osmosys dot tv CC: gcc-bugs at gcc dot gnu dot org GCC host triplet: i386-redhat-linux GCC target triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22266