Bug 50396 - SSE division by zero generates incorrect code with optimizations enabled
Summary: SSE division by zero generates incorrect code with optimizations enabled
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.3
Assignee: Richard Biener
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-09-14 16:16 UTC by Mathias Gaunard
Modified: 2011-12-23 09:19 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*
Build:
Known to work: 4.6.3, 4.7.0
Known to fail: 4.5.2, 4.6.2
Last reconfirmed: 2011-10-20 00:00:00


Attachments
divide by zero example (146 bytes, text/x-csrc)
2011-09-14 16:16 UTC, Mathias Gaunard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mathias Gaunard 2011-09-14 16:16:19 UTC
Created attachment 25273 [details]
divide by zero example

The attached C code, written using SSE intrinsics, prints -nan when no optimizations are used (as expected) and 0 otherwise.

It seems constant folding of the divps instruction doesn't do the right thing.

It works correctly when the first argument is non-zero though (including minus zero).
Comment 1 Mathias Gaunard 2011-10-20 08:58:19 UTC
This bug has stayed as unconfirmed for a while.
Is there anything that I could do to help?
Comment 2 Richard Biener 2011-10-20 09:11:06 UTC
Confirmed.  Broken by CSE1 on RTL at -O1.
Comment 3 Richard Biener 2011-10-20 09:13:21 UTC
    case DIV:
      /* Handle floating point and integers separately.  */
      if (SCALAR_FLOAT_MODE_P (mode))
        {

should probably be FLOAT_MODE_P (mode).
Comment 4 Mathias Gaunard 2011-12-22 15:01:02 UTC
What's missing to get this fixed?

Previous comment suggests the fix is trivial.
Comment 5 Richard Biener 2011-12-22 15:14:32 UTC
Sorry, forgot about this issue.
Comment 6 Richard Biener 2011-12-23 09:10:27 UTC
Author: rguenth
Date: Fri Dec 23 09:10:18 2011
New Revision: 182653

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182653
Log:
2011-12-23  Richard Guenther  <rguenther@suse.de>

	PR rtl-optimization/50396
	* simplify-rtx.c (simplify_binary_operation_1): Properly
	guard code that only works for integers.

	* gcc.dg/torture/pr50396.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/torture/pr50396.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/simplify-rtx.c
    trunk/gcc/testsuite/ChangeLog
Comment 7 Richard Biener 2011-12-23 09:16:16 UTC
Author: rguenth
Date: Fri Dec 23 09:16:08 2011
New Revision: 182654

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182654
Log:
2011-12-23  Richard Guenther  <rguenther@suse.de>

	PR rtl-optimization/50396
	* simplify-rtx.c (simplify_binary_operation_1): Properly
	guard code that only works for integers.

	* gcc.dg/torture/pr50396.c: New testcase.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/torture/pr50396.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/simplify-rtx.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 8 Richard Biener 2011-12-23 09:19:30 UTC
Fixed for 4.6.3.