From b80280f2c568097c1da9aacd9b540f74ad91cf22 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 18 Mar 2008 16:10:24 +0000 Subject: 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 * 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 --- gcc/tree-ssa-forwprop.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'gcc/tree-ssa-forwprop.c') diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c index 5108cfc..1766869 100644 --- a/gcc/tree-ssa-forwprop.c +++ b/gcc/tree-ssa-forwprop.c @@ -218,14 +218,28 @@ get_prop_source_stmt (tree name, bool single_use_only, bool *single_use_p) /* 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); } @@ -245,6 +259,10 @@ can_propagate_from (tree def_stmt) 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))) { -- cgit v1.1