Bug 31152 - -(x>y) generates wrong code
-(x>y) generates wrong code
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: target
4.1.2
: P3 normal
: 4.3.0
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-03-12 17:36 UTC by anton
Modified: 2007-06-23 19:07 UTC (History)
4 users (show)

See Also:
Host: arm-linux-gnu
Target: arm-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-06-19 09:41:02


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description anton 2007-03-12 17:36:01 UTC
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.
Comment 1 anton 2007-03-12 17:43:43 UTC
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);
}

Comment 2 Richard Biener 2007-03-13 10:20:03 UTC
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.
Comment 3 Frank Buss 2007-03-23 21:27:49 UTC
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".
Comment 4 Richard Earnshaw 2007-06-19 09:41:02 UTC
Confirmed.  This is a bug in the negscc pattern in arm.md.  It's only been there since 1994!
Comment 5 Richard Earnshaw 2007-06-23 18:07:17 UTC
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

Comment 6 Richard Earnshaw 2007-06-23 18:11:41 UTC
Fixed on trunk.
Comment 7 Martin Michlmayr 2007-06-23 19:07:14 UTC
Are you not going to apply this to 4.1 and 4.2?
Comment 8 Martin Michlmayr 2007-06-23 19:07:49 UTC
Richard, I think this patch should also be added to the 4.1 and 4.2 branches.