aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-pre.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2008-03-18 16:10:24 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2008-03-18 16:10:24 +0000
commitb80280f2c568097c1da9aacd9b540f74ad91cf22 (patch)
tree1e20a972378312ce4158563ae53589c5b3dda789 /gcc/tree-ssa-pre.c
parent2e28e797125a94c7587b599eba438015fa02e5fe (diff)
downloadgcc-b80280f2c568097c1da9aacd9b540f74ad91cf22.zip
gcc-b80280f2c568097c1da9aacd9b540f74ad91cf22.tar.gz
gcc-b80280f2c568097c1da9aacd9b540f74ad91cf22.tar.bz2
tree-ssa-sccvn.c (visit_reference_op_load): If the lookup found an expression with constants, note that in the VN for the lhs.
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. * gcc.dg/tree-ssa/forwprop-4.c: New testcase. * gcc.dg/tree-ssa/ssa-fre-16.c: Likewise. From-SVN: r133315
Diffstat (limited to 'gcc/tree-ssa-pre.c')
-rw-r--r--gcc/tree-ssa-pre.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index 616627c..ad628a3 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -3605,10 +3605,11 @@ do_SCCVN_insertion (tree stmt, tree ssa_vn)
/* Eliminate fully redundant computations. */
-static void
+static unsigned int
eliminate (void)
{
basic_block b;
+ unsigned int todo = 0;
FOR_EACH_BB (b)
{
@@ -3689,8 +3690,46 @@ eliminate (void)
}
}
}
+ /* 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.
@@ -3931,9 +3970,10 @@ fini_pre (void)
/* 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);
@@ -3947,7 +3987,7 @@ execute_pre (bool do_fre)
if (!do_fre)
remove_dead_inserted_code ();
fini_pre ();
- return;
+ return 0;
}
switch_to_PRE_table ();
compute_avail ();
@@ -3978,7 +4018,7 @@ execute_pre (bool do_fre)
}
/* Remove all the redundant expressions. */
- eliminate ();
+ todo |= eliminate ();
if (dump_file && (dump_flags & TDF_STATS))
{
@@ -3999,6 +4039,8 @@ execute_pre (bool do_fre)
}
fini_pre ();
+
+ return todo;
}
/* Gate and execute functions for PRE. */
@@ -4006,8 +4048,7 @@ execute_pre (bool do_fre)
static unsigned int
do_pre (void)
{
- execute_pre (false);
- return TODO_rebuild_alias;
+ return TODO_rebuild_alias | execute_pre (false);
}
static bool
@@ -4041,8 +4082,7 @@ struct tree_opt_pass pass_pre =
static unsigned int
execute_fre (void)
{
- execute_pre (true);
- return 0;
+ return execute_pre (true);
}
static bool