This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, Fix PR 31098] a*C == b*C is not foldded to a == b with --fast-math/floating point
- From: Pranav Bhandarkar <pranav dot bhandarkar at celunite dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 07 Oct 2007 21:46:44 +0530
- Subject: Re: [PATCH, Fix PR 31098] a*C == b*C is not foldded to a == b with --fast-math/floating point
- References: <470900FD.1090105@celunite.com>
And ofcourse bootstrapped and regtested on i686-pc-linux-gnu.
Thanks,
Pranav
Pranav Bhandarkar
GNU Tools
Celunite, Inc.
(www.celunite.com)
+91-98220 82881
Pranav Bhandarkar wrote:
Hi,
Could somebody please review this patch which is a proposed fix for PR
31098.
2007-10-07 Pranav Bhandarkar <pranav.bhandarkar@celunite.com>
* fold-const.c (fold_comparison): fold (a OP c) CMP (b OP c) -> a
CMP b, iff c is not zero
* testsuite/pr31098.c: New
Thanks,
Pranav
------------------------------------------------------------------------
Index: fold-const.c
===================================================================
--- fold-const.c (revision 128907)
+++ fold-const.c (working copy)
@@ -9048,6 +9048,23 @@
return fold_build2 (code, type, TREE_OPERAND (arg1, 0),
TREE_OPERAND (arg0, 0));
+ /* (a OP c) CMP (b OP c) -> a CMP b, iff c is not zero */
+ if (fast_math_flags_set_p () && (TREE_CODE (arg0) == TREE_CODE (arg1))
+ && BINARY_CLASS_P (arg0) && !real_zerop (TREE_OPERAND (arg0,1)))
+ {
+ if (TREE_CODE (TREE_OPERAND (arg0, 1)) == REAL_CST
+ && TREE_CODE (TREE_OPERAND (arg1, 1)) == REAL_CST )
+ {
+ REAL_VALUE_TYPE *cst0, *cst1;
+ cst0 = &TREE_REAL_CST (TREE_OPERAND (arg0, 1));
+ cst1 = &TREE_REAL_CST (TREE_OPERAND (arg1, 1));
+
+ if (real_compare (EQ_EXPR, cst0, cst1))
+ return fold_build2 (code, type, TREE_OPERAND (arg0,0), TREE_OPERAND (arg1,0));
+
+ }
+ }
+
if (TREE_CODE (arg1) == REAL_CST)
{
REAL_VALUE_TYPE cst;
------------------------------------------------------------------------
--- /dev/null 2006-05-22 19:55:23.000000000 +0530
+++ pr31098.c 2007-10-07 21:01:37.000000000 +0530
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original --fast-math" } */
+
+int f(float a, float b)
+{
+ return a*10 == b*10;
+}
+
+
+/* { dg-final { scan-tree-dump-times "return a == b" 1 "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */