This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[tree-ssa] tree-ssa-dom.c: Fix PR 14303.


Hi,

Attached is a patch to fix PR optimization/14303.

Consider:

void
foo (double x)
{
  double p, q;

  p = fabs (x);
  q = 0.0;
  if (p < q)
    link_error ();
}

Without the patch, the tree-ssa cannot fold p < q.  With the patch,
dom1 gives me:

foo (x)
{
  double q;
  double p;

<bb 0>:
  p_2 = ABS_EXPR <x_1>;
  q_3 = 0.0;
  return;

}

I put this optimization in simplify_cond_and_lookup_avail_expr, but
I'm not sure if this is the right place as the only machinery I need
is SSA_NAME_DEF_STMT.  I thought I should do this in fold, but
applying Steven's patch in PR 14303 didn't work.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-03-05  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-ssa-dom.c (simplify_cond_and_lookup_avail_expr): Fold
	abs (x) < 0.0 into false.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.145
diff -u -r1.1.2.145 tree-ssa-dom.c
--- tree-ssa-dom.c	2 Mar 2004 18:41:49 -0000	1.1.2.145
+++ tree-ssa-dom.c	6 Mar 2004 01:07:30 -0000
@@ -1959,6 +1959,18 @@
 		}
 	    }
 
+	  /* abs (x) < 0.0 is always false.  */
+	  if (TREE_CODE (cond) == LT_EXPR
+	      && TREE_CODE (op1) == REAL_CST
+	      && REAL_VALUES_EQUAL (TREE_REAL_CST (op1), dconst0))
+	    {
+	      tree def = SSA_NAME_DEF_STMT (op0);
+
+	      if (TREE_CODE (def) == MODIFY_EXPR
+		  && TREE_CODE (TREE_OPERAND (def, 1)) == ABS_EXPR)
+		return boolean_false_node;
+	    }
+
 	  /* Consult the value range records for this variable (if they exist)
 	     to see if we can eliminate or simplify this conditional. 
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]