This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Constant folding x != x tweaks.
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Joern Rennecke <joern dot rennecke at superh dot com>
- Date: Mon, 9 Jun 2003 20:50:39 -0600 (MDT)
- Subject: [PATCH] Constant folding x != x tweaks.
It comes as a bit of a surprise that we never constant fold x == x
or x != x at the tree-level when x has a floating point type. This
patch modifies the clauses to match the usual idiom, so that we fold
EQ_EXPR and NE_EXPR with either -ffast-math or -ffinite-math-only.
This should fix (or work-around) Joern's current failures of
builtins-19.c on sh-elf, where I'd assumed we were already constant
folding floating point equality with -ffast-math. In actuality,
these comparisons were only being folded by the RTL optimizers, but
only on platforms where the RTL wasn't too obfuscated.
The following patch has been tested with a full bootstrap, all
languages except treelang, on i686-pc-linux-gnu, and regression
tested with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-06-09 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold <EQ_EXPR): Don't fold x == x only if x
is a floating point type *and* we currently honor NaNs.
(fold <NE_EXPR>): Likewise.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.255
diff -c -3 -p -r1.255 fold-const.c
*** fold-const.c 6 Jun 2003 12:36:22 -0000 1.255
--- fold-const.c 9 Jun 2003 22:41:25 -0000
*************** fold (expr)
*** 7036,7050 ****
case EQ_EXPR:
case GE_EXPR:
case LE_EXPR:
! if (! FLOAT_TYPE_P (TREE_TYPE (arg0)))
return constant_boolean_node (1, type);
code = EQ_EXPR;
TREE_SET_CODE (t, code);
break;
case NE_EXPR:
! /* For NE, we can only do this simplification if integer. */
! if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
break;
/* ... fall through ... */
case GT_EXPR:
--- 7036,7053 ----
case EQ_EXPR:
case GE_EXPR:
case LE_EXPR:
! if (! FLOAT_TYPE_P (TREE_TYPE (arg0))
! || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))))
return constant_boolean_node (1, type);
code = EQ_EXPR;
TREE_SET_CODE (t, code);
break;
case NE_EXPR:
! /* For NE, we can only do this simplification if integer
! or we don't honor IEEE floating point NaNs. */
! if (FLOAT_TYPE_P (TREE_TYPE (arg0))
! && HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))))
break;
/* ... fall through ... */
case GT_EXPR:
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833