Thread View: gnu.gcc.bug
1 messages
1 total messages
Started by Paul Eggert
Tue, 11 Aug 1992 04:09
GCC 2.2.2 wrongly optimizes X?X: 0 to X when X is IEEE -0.0
Author: Paul Eggert
Date: Tue, 11 Aug 1992 04:09
Date: Tue, 11 Aug 1992 04:09
45 lines
2177 bytes
2177 bytes
For the program:
double normalize(x) double x; { return x ? x : 0; }
main() { printf("%g\n", normalize(-0.0)); }
GCC 2.2.2 (sparc, SunOS 4.1.2, with the -O option) generates code that outputs
`-0'. It should output `0'. The problem is that X?X:0 is being optimized to
X; but this optimization is incorrect when X is -0.0, because -0.0?-0.0:0
should yield 0. Here is a patch.
Tue Aug 11 04:02:51 1992 Paul Eggert (eggert@twinsun.com)
* fold-const.c (fold): Don't fold (A op B ? A : C) if A is IEEE
floating point, because A might be -0.0 or NaN.
===================================================================
RCS file: fold-const.c,v
retrieving revision 2.2.2.1
diff -c -r2.2.2.1 fold-const.c
*** fold-const.c 1992/07/03 19:36:20 2.2.2.1
--- fold-const.c 1992/08/11 04:02:51
***************
*** 3729,3737 ****
/* If we have A op B ? A : C, we may be able to convert this to a
simpler expression, depending on the operation and the values
! of B and C. */
if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
arg1, TREE_OPERAND (arg0, 1)))
{
--- 3729,3740 ----
/* If we have A op B ? A : C, we may be able to convert this to a
simpler expression, depending on the operation and the values
! of B and C. IEEE floating point prevents this though,
! because A or B might be -0.0 or a NaN. */
if (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
+ && (TARGET_FLOAT_FORMAT != IEEE_FLOAT_FORMAT
+ || TREE_CODE (TREE_TYPE (TREE_OPERAND (arg0, 0))) != REAL_TYPE)
&& operand_equal_for_comparison_p (TREE_OPERAND (arg0, 0),
arg1, TREE_OPERAND (arg0, 1)))
{
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads