This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
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
This one has been bootstrapped/regtested on x86_64-suse-linux.
2007-07-11 Eric Botcazou <ebotcazou@adacore.com>
PR tree-optimization/32589
* doc/tree-ssa.texi (Rough GIMPLE Grammar): Add missing rule.
* tree-gimple.c (is_gimple_min_invariant): Clarify head comment.
* tree-ssa-propagate.c (valid_gimple_expression_p): New
predicate, extracted from...
(set_rhs): ...here. Call it for the expression on entry.
* tree-ssa-propagate.h (valid_gimple_expression_p): Declare.
* tree-ssa-sccvn.c: Include tree-ssa-propagate.h.
(simplify_binary_expression): Use valid_gimple_expression_p
to validate the simplification.
* Makefile.in (tree-ssa-sccvn.o): Depends on tree-ssa-propagate.h.
2007-07-11 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/invariant_index.ad[sb]: New testcase.
--
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 && valid_gimple_expression_p (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,17 @@ 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. */
bool
-set_rhs (tree *stmt_p, tree expr)
+valid_gimple_expression_p (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 +658,25 @@ 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;
+
+ if (!valid_gimple_expression_p (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 valid_gimple_expression_p (tree expr);
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
package P is
Name_Buffer : String (1 .. 100);
Name_Len : Natural;
procedure Proc (S : String);
end P;
-- { dg-do compile }
-- { dg-options "-O -gnatp" }
package body P is
procedure Proc (S : String) is
N : constant Integer := S'Length;
begin
Name_Buffer (1 + N .. Name_Len + N) := Name_Buffer (1 .. Name_Len);
Name_Buffer (1 .. N) := S;
Name_Len := Name_Len + N;
end;
end P;