+2008-03-18 Richard Guenther <rguenther@suse.de>
+
+ * tree-ssa-sccvn.c (visit_reference_op_load): If the lookup
+ found an expression with constants, note that in the VN for the lhs.
+ * tree-ssa-pre.c (eliminate): Visit COND_EXPR statements and
+ fold them to constants if possible. Run cleanup_cfg if done so.
+ (execute_pre): Return todo.
+ (do_pre): Likewise.
+ (execute_fre): Likewise.
+ * tree-ssa-forwprop.c (can_propagate_from): Allow propagation
+ of constants.
+ (get_prop_source_stmt): Look through pointer conversions.
+
2008-03-18 Jan Hubicka <jh@suse.cz>
* tree-pretty-print.c: Include predict.h.
+2008-03-18 Richard Guenther <rguenther@suse.de>
+
+ * gcc.dg/tree-ssa/forwprop-4.c: New testcase.
+ * gcc.dg/tree-ssa/ssa-fre-16.c: Likewise.
+
2008-03-18 Richard Guenther <rguenther@suse.de>
* gcc.dg/tree-ssa/loop-19.c: Revert previous change.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-forwprop1" } */
+
+/* We should be able to fold the comparison at least with the
+ first forwprop pass, if not a ccp pass before. */
+
+extern void link_error (void);
+void foo()
+{
+ int i;
+ char *p = (char *)&i;
+ long *q = (long *)p;
+ if (q == 0)
+ link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "forwprop1" } } */
+/* { dg-final { cleanup-tree-dump "forwprop1" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre" } */
+
+/* FRE should be able to combine i and j and perform simplification
+ on the condition. */
+
+extern void link_error (void);
+int i;
+int foo(int b, int c)
+{
+ i = b + 1;
+ int j = i - 1;
+ if (b != j)
+ link_error ();
+}
+
+/* { dg-final { scan-tree-dump-not "link_error" "fre" } } */
+/* { dg-final { cleanup-tree-dump "fre" } } */
/* If name is not a simple copy destination, we found it. */
if (TREE_CODE (GIMPLE_STMT_OPERAND (def_stmt, 1)) != SSA_NAME)
{
+ tree rhs;
+
if (!single_use_only && single_use_p)
*single_use_p = single_use;
- return def_stmt;
+ /* We can look through pointer conversions in the search
+ for a useful stmt for the comparison folding. */
+ rhs = GIMPLE_STMT_OPERAND (def_stmt, 1);
+ if ((TREE_CODE (rhs) == NOP_EXPR
+ || TREE_CODE (rhs) == CONVERT_EXPR)
+ && TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
+ && POINTER_TYPE_P (TREE_TYPE (rhs))
+ && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (rhs, 0))))
+ name = TREE_OPERAND (rhs, 0);
+ else
+ return def_stmt;
+ }
+ else
+ {
+ /* Continue searching the def of the copy source name. */
+ name = GIMPLE_STMT_OPERAND (def_stmt, 1);
}
-
- /* Continue searching the def of the copy source name. */
- name = GIMPLE_STMT_OPERAND (def_stmt, 1);
} while (1);
}
if (REFERENCE_CLASS_P (rhs))
return false;
+ /* Constants can be always propagated. */
+ if (is_gimple_min_invariant (rhs))
+ return true;
+
/* We cannot propagate ssa names that occur in abnormal phi nodes. */
switch (TREE_CODE_LENGTH (TREE_CODE (rhs)))
{
/* Eliminate fully redundant computations. */
-static void
+static unsigned int
eliminate (void)
{
basic_block b;
+ unsigned int todo = 0;
FOR_EACH_BB (b)
{
}
}
}
+ /* Visit COND_EXPRs and fold the comparison with the
+ available value-numbers. */
+ else if (TREE_CODE (stmt) == COND_EXPR
+ && COMPARISON_CLASS_P (COND_EXPR_COND (stmt)))
+ {
+ tree cond = COND_EXPR_COND (stmt);
+ tree op0 = TREE_OPERAND (cond, 0);
+ tree op1 = TREE_OPERAND (cond, 1);
+ tree result;
+
+ if (TREE_CODE (op0) == SSA_NAME)
+ op0 = VN_INFO (op0)->valnum;
+ if (TREE_CODE (op1) == SSA_NAME)
+ op1 = VN_INFO (op1)->valnum;
+ result = fold_binary (TREE_CODE (cond), TREE_TYPE (cond),
+ op0, op1);
+ if (result && TREE_CODE (result) == INTEGER_CST)
+ {
+ COND_EXPR_COND (stmt) = result;
+ update_stmt (stmt);
+ todo = TODO_cleanup_cfg;
+ }
+ }
+ else if (TREE_CODE (stmt) == COND_EXPR
+ && TREE_CODE (COND_EXPR_COND (stmt)) == SSA_NAME)
+ {
+ tree op = COND_EXPR_COND (stmt);
+ op = VN_INFO (op)->valnum;
+ if (TREE_CODE (op) == INTEGER_CST)
+ {
+ COND_EXPR_COND (stmt) = integer_zerop (op)
+ ? boolean_false_node : boolean_true_node;
+ update_stmt (stmt);
+ todo = TODO_cleanup_cfg;
+ }
+ }
}
}
+
+ return todo;
}
/* Borrow a bit of tree-ssa-dce.c for the moment.
/* Main entry point to the SSA-PRE pass. DO_FRE is true if the caller
only wants to do full redundancy elimination. */
-static void
+static unsigned int
execute_pre (bool do_fre)
{
+ unsigned int todo = 0;
do_partial_partial = optimize > 2;
init_pre (do_fre);
if (!do_fre)
remove_dead_inserted_code ();
fini_pre ();
- return;
+ return 0;
}
switch_to_PRE_table ();
compute_avail ();
}
/* Remove all the redundant expressions. */
- eliminate ();
+ todo |= eliminate ();
if (dump_file && (dump_flags & TDF_STATS))
{
}
fini_pre ();
+
+ return todo;
}
/* Gate and execute functions for PRE. */
static unsigned int
do_pre (void)
{
- execute_pre (false);
- return TODO_rebuild_alias;
+ return TODO_rebuild_alias | execute_pre (false);
}
static bool
static unsigned int
execute_fre (void)
{
- execute_pre (true);
- return 0;
+ return execute_pre (true);
}
static bool
if (result)
{
changed = set_ssa_val_to (lhs, result);
+ if (TREE_CODE (result) == SSA_NAME
+ && VN_INFO (result)->has_constants)
+ {
+ VN_INFO (lhs)->expr = VN_INFO (result)->expr;
+ VN_INFO (lhs)->has_constants = true;
+ }
}
else
{