Article View: gnu.gcc.bug
Article #335GCC 2.2.2 wrongly optimizes X?X: 0 to X when X is IEEE -0.0
From: 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)))
{
Technical Details
Message-ID:
<9208110409.AA24365@farside.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggertShow Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!twinsun.COM!eggert From: eggert@twinsun.COM (Paul Eggert) Subject: GCC 2.2.2 wrongly optimizes X?X: 0 to X when X is IEEE -0.0 Message-ID: <9208110409.AA24365@farside.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Tue, 11 Aug 1992 04:09:43 GMT Approved: bug-gcc@prep.ai.mit.edu Lines: 46