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]

Re: [PATCH] Fix PR tree-optimization/32589


> > Or FRE should do what other passes do and use set_rhs () to verify if the
> > resulting trees are sufficiently gimple
>
> Indeed, looks like Tree-CCP already faced the problem and solved it.  I'm
> going to try something along these lines.

I can propose this, very lightly tested.


	* tree-ssa-propagate.c (is_valid_gimple_rhs_after_folding): New
	predicate, extracted from...
	(set_rhs): ...here.  Call it on the expression.
	* tree-ssa-propagate.h (is_valid_gimple_rhs_after_folding): Declare.
	* tree-ssa-sccvn.c: Include tree-ssa-propagate.h.
	(simplify_binary_expression): Use is_valid_gimple_rhs_after_folding
	to validate the simplification.
	* Makefile.in (tree-ssa-sccvn.o): Depends on tree-ssa-propagate.h.


-- 
Eric Botcazou
Index: doc/tree-ssa.texi
===================================================================
--- doc/tree-ssa.texi	(revision 126511)
+++ doc/tree-ssa.texi	(working copy)
@@ -1,4 +1,4 @@
-@c Copyright (c) 2004, 2005 Free Software Foundation, Inc.
+@c Copyright (c) 2004, 2005, 2007 Free Software Foundation, Inc.
 @c Free Software Foundation, Inc.
 @c This is part of the GCC manual.
 @c For copying conditions, see the file gcc.texi.
@@ -680,7 +680,7 @@ void f()
    bitfieldref  : BIT_FIELD_REF
                         op0 -> inner-compref
                         op1 -> CONST
-                        op2 -> var
+                        op2 -> val
 
    compref      : inner-compref
                 | TARGET_MEM_REF
@@ -718,6 +718,8 @@ void f()
                         op1 -> val
 
    val          : ID
+                | invariant ADDR_EXPR
+                        op0 -> addr-expr-arg
                 | CONST
 
    rhs          : lhs
Index: tree-gimple.c
===================================================================
--- tree-gimple.c	(revision 126511)
+++ tree-gimple.c	(working copy)
@@ -166,7 +166,7 @@ is_gimple_addressable (tree t)
 	  || INDIRECT_REF_P (t));
 }
 
-/* Return true if T is function invariant.  Or rather a restricted
+/* Return true if T is a GIMPLE minimal invariant.  It's a restricted
    form of function invariant.  */
 
 bool
Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c	(revision 126511)
+++ tree-ssa-sccvn.c	(working copy)
@@ -43,6 +43,7 @@ Boston, MA 02110-1301, USA.  */
 #include "bitmap.h"
 #include "langhooks.h"
 #include "cfgloop.h"
+#include "tree-ssa-propagate.h"
 #include "tree-ssa-sccvn.h"
 
 /* This algorithm is based on the SCC algorithm presented by Keith
@@ -1397,42 +1398,16 @@ simplify_binary_expression (tree rhs)
       else if (SSA_VAL (op1) != VN_TOP && SSA_VAL (op1) != op1)
 	op1 = VN_INFO (op1)->valnum;
     }
+
   result = fold_binary (TREE_CODE (rhs), TREE_TYPE (rhs), op0, op1);
 
   /* Make sure result is not a complex expression consisting
      of operators of operators (IE (a + b) + (a + c))
      Otherwise, we will end up with unbounded expressions if
      fold does anything at all.  */
-  if (result)
-    {
-      if (is_gimple_min_invariant (result))
-	return result;
-      else if (SSA_VAR_P (result))
-	return result;
-      else if (EXPR_P (result))
-	{
-	  switch (TREE_CODE_CLASS (TREE_CODE (result)))
-	    {
-	    case tcc_unary:
-	      {
-		tree op0 = TREE_OPERAND (result, 0);
-		if (!EXPR_P (op0))
-		  return result;
-	      }
-	      break;
-	    case tcc_binary:
-	      {
-		tree op0 = TREE_OPERAND (result, 0);
-		tree op1 = TREE_OPERAND (result, 1);
-		if (!EXPR_P (op0) && !EXPR_P (op1))
-		  return result;
-	      }
-	      break;
-	    default:
-	      break;
-	    }
-	}
-    }
+  if (result && is_valid_gimple_rhs_after_folding (result))
+    return result;
+
   return NULL_TREE;
 }
 
Index: tree-ssa-propagate.c
===================================================================
--- tree-ssa-propagate.c	(revision 126511)
+++ tree-ssa-propagate.c	(working copy)
@@ -573,24 +573,19 @@ get_rhs (tree stmt)
 }
 
 
-/* Set the main expression of *STMT_P to EXPR.  If EXPR is not a valid
-   GIMPLE expression no changes are done and the function returns
-   false.  */
+/* Return true if EXPR is a valid GIMPLE expression for the rhs,
+   false otherwise.  EXPR is assumed to be the folded result of
+   a combination of GIMPLE expressions.  */
 
 bool
-set_rhs (tree *stmt_p, tree expr)
+is_valid_gimple_rhs_after_folding (tree expr)
 {
-  tree stmt = *stmt_p, op;
   enum tree_code code = TREE_CODE (expr);
-  stmt_ann_t ann;
-  tree var;
-  ssa_op_iter iter;
 
-  /* Verify the constant folded result is valid gimple.  */
   switch (TREE_CODE_CLASS (code))
     {
     case tcc_declaration:
-      if (!is_gimple_variable(expr))
+      if (!is_gimple_variable (expr))
 	return false;
       break;
 
@@ -665,6 +660,26 @@ set_rhs (tree *stmt_p, tree expr)
       return false;
     }
 
+  return true;
+}
+
+
+/* Set the main expression of *STMT_P to EXPR.  If EXPR is not a valid
+   GIMPLE expression no changes are done and the function returns
+   false.  */
+
+bool
+set_rhs (tree *stmt_p, tree expr)
+{
+  tree stmt = *stmt_p, op;
+  stmt_ann_t ann;
+  tree var;
+  ssa_op_iter iter;
+
+  /* Verify that the folded result is valid gimple.  */
+  if (!is_valid_gimple_rhs_after_folding (expr))
+    return false;
+
   if (EXPR_HAS_LOCATION (stmt)
       && (EXPR_P (expr)
 	  || GIMPLE_STMT_P (expr))
Index: tree-ssa-propagate.h
===================================================================
--- tree-ssa-propagate.h	(revision 126511)
+++ tree-ssa-propagate.h	(working copy)
@@ -114,6 +114,7 @@ typedef enum ssa_prop_result (*ssa_prop_
 /* In tree-ssa-propagate.c  */
 void ssa_propagate (ssa_prop_visit_stmt_fn, ssa_prop_visit_phi_fn);
 tree get_rhs (tree);
+bool is_valid_gimple_rhs_after_folding (tree);
 bool set_rhs (tree *, tree);
 tree first_vdef (tree);
 bool stmt_makes_single_load (tree);
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 126511)
+++ Makefile.in	(working copy)
@@ -2042,7 +2042,7 @@ tree-ssa-sccvn.o : tree-ssa-sccvn.c $(TR
    $(SYSTEM_H) $(TREE_H) $(GGC_H) $(DIAGNOSTIC_H) $(TIMEVAR_H) \
    $(TM_H) coretypes.h $(TREE_DUMP_H) tree-pass.h $(FLAGS_H) $(CFGLOOP_H) \
    alloc-pool.h $(BASIC_BLOCK_H) bitmap.h $(HASHTAB_H) $(TREE_GIMPLE_H) \
-   $(TREE_INLINE_H) tree-iterator.h tree-ssa-sccvn.h
+   $(TREE_INLINE_H) tree-iterator.h tree-ssa-propagate.h tree-ssa-sccvn.h
 tree-vn.o : tree-vn.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(GGC_H) \
    $(TREE_H) $(TREE_FLOW_H) $(HASHTAB_H) langhooks.h tree-pass.h \
    $(TREE_DUMP_H) $(DIAGNOSTIC_H) tree-ssa-sccvn.h

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