summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-forwprop.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2008-03-18 16:10:24 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2008-03-18 16:10:24 +0000
commitb9e98b8aaf6868b21168913ea3d82df38d4d1430 (patch)
tree1e20a972378312ce4158563ae53589c5b3dda789 /gcc/tree-ssa-forwprop.c
parent4a1849e3a1e51cb463703ec17861392086dce70b (diff)
downloadgcc-b9e98b8aaf6868b21168913ea3d82df38d4d1430.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@133315 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-forwprop.c')
-rw-r--r--gcc/tree-ssa-forwprop.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/gcc/tree-ssa-forwprop.c b/gcc/tree-ssa-forwprop.c
index 5108cfcd6f2..1766869d0c4 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)))
{