The actual gcc version is gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) When compiled and run with this gcc version, using the command line gcc -O xxx.c && a.out the attached program outputs -1, whereas the correct output is 0. If I use gcc 3.3.6 or leave away the -O flag, the program produces correct output.
Subject: Re: New: -(x>y) generates wrong code I cannot create an attachment in Bugzilla, so I'll just append the test program here: #include <stdio.h> #include <limits.h> long foo(long x, long y); int main() { printf("%d\n",foo(INT_MIN,INT_MAX)); return 0; } long foo(long x, long y) { return -(x>y); }
It works for me on x86_64 and i686 with 4.0.0, 4.1.0 and 4.1.2. So this looks like a target issue.
I can reproduce the problem on a Linkstation Pro with an ARM926EJ CPU. I compiled GCC SVN revision 123155 from the gcc-4_2-branch on it. Creating wrong assembler code is at least a major bug, even when using the optimizing switch (which many programs do), so please change severity to "major".
Confirmed. This is a bug in the negscc pattern in arm.md. It's only been there since 1994!
Subject: Bug 31152 Author: rearnsha Date: Sat Jun 23 18:07:04 2007 New Revision: 125973 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=125973 Log: PR target/31152 * arm.md (negscc): Match the correct operand for optimized LT0 test. Remove optimization for GT. *gcc.c-torture/execute/20070623-1.c: New. Added: trunk/gcc/testsuite/gcc.c-torture/execute/20070623-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/arm/arm.md trunk/gcc/testsuite/ChangeLog
Fixed on trunk.
Are you not going to apply this to 4.1 and 4.2?
Richard, I think this patch should also be added to the 4.1 and 4.2 branches.