summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-dom.c
diff options
context:
space:
mode:
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2004-05-18 02:53:55 +0000
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2004-05-18 02:53:55 +0000
commit6e9a4371f72c47837ec18b3d6ae8eb375487b242 (patch)
tree8b09f05de2af4fbf629836a3810db742dd217646 /gcc/tree-ssa-dom.c
parent49fbf4b925552657ef9fe53d8382dfc5d9723ac5 (diff)
downloadgcc-6e9a4371f72c47837ec18b3d6ae8eb375487b242.tar.gz
* toplev.h (flag_delete_null_pointer_checks): Move from here to...
* flags.h (flag_delete_null_pointer_checks): Here. * tree-flow.h (cprop_into_successor_phis): Add argument to prototype. * tree-phinodes.c (resize_phi_node): Initialize PHI_ARG_NONZERO. (add_phi_arg, remove_phi_arg_num): Similarly. * tree-ssa-copy.c (cprop_into_successor_phis): Propagate nonzero property into PHI nodes. * tree-ssa-dom.c: Remove redundant inclusion of flags.h. (record_equivalences_from_phis): If all PHI arguments are known to be nonzero, then the result must be nonzero as well. (cprop_into_phis): Pass nonzero_vars bitmap to cprop_into_successor_phis (record_equivalences_from_stmt): Check flag_delete_null_pointer_checks appropriately. Walk the USE-DEF chains and propagate nonzero property as appropriate. * tree.h (PHI_ARG_NONZERO): Define. (phi_arg_d): Add nonzero flag. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81968 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-dom.c')
-rw-r--r--gcc/tree-ssa-dom.c73
1 files changed, 51 insertions, 22 deletions
diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c
index 5f8896f7019..3ecb8e0a3f9 100644
--- a/gcc/tree-ssa-dom.c
+++ b/gcc/tree-ssa-dom.c
@@ -40,7 +40,6 @@ Boston, MA 02111-1307, USA. */
#include "domwalk.h"
#include "real.h"
#include "tree-pass.h"
-#include "flags.h"
#include "langhooks.h"
/* This file implements optimizations on the dominator tree. */
@@ -1314,7 +1313,12 @@ dom_opt_finalize_block (struct dom_walk_data *walk_data, basic_block bb)
Ignoring any alternatives which are the same as the result, if
all the alternatives are equal, then the PHI node creates an
- equivalence. */
+ equivalence.
+
+ Additionally, if all the PHI alternatives are known to have a nonzero
+ value, then the result of this PHI is known to have a nonzero value,
+ even if we do not know its exact value. */
+
static void
record_equivalences_from_phis (struct dom_walk_data *walk_data, basic_block bb)
{
@@ -1367,6 +1371,17 @@ record_equivalences_from_phis (struct dom_walk_data *walk_data, basic_block bb)
&& may_propagate_copy (lhs, rhs))
set_value_for (lhs, rhs, const_and_copies);
+ /* Now see if we know anything about the nonzero property for the
+ result of this PHI. */
+ for (i = 0; i < PHI_NUM_ARGS (phi); i++)
+ {
+ if (!PHI_ARG_NONZERO (phi, i))
+ break;
+ }
+
+ if (i == PHI_NUM_ARGS (phi))
+ bitmap_set_bit (nonzero_vars, SSA_NAME_VERSION (PHI_RESULT (phi)));
+
register_new_def (lhs, &bd->block_defs);
}
}
@@ -2257,7 +2272,7 @@ static void
cprop_into_phis (struct dom_walk_data *walk_data ATTRIBUTE_UNUSED,
basic_block bb)
{
- cprop_into_successor_phis (bb, const_and_copies);
+ cprop_into_successor_phis (bb, const_and_copies, nonzero_vars);
}
/* Search for redundant computations in STMT. If any are found, then
@@ -2422,25 +2437,39 @@ record_equivalences_from_stmt (tree stmt,
/* Look at both sides for pointer dereferences. If we find one, then
the pointer must be nonnull and we can enter that equivalence into
the hash tables. */
- for (i = 0; i < 2; i++)
- {
- tree t = TREE_OPERAND (stmt, i);
-
- /* Strip away any COMPONENT_REFs. */
- while (TREE_CODE (t) == COMPONENT_REF)
- t = TREE_OPERAND (t, 0);
-
- /* Now see if this is a pointer dereference. */
- if (TREE_CODE (t) == INDIRECT_REF)
- {
- tree op = TREE_OPERAND (t, 0);
-
- /* If the pointer is a SSA variable, then enter new
- equivalences into the hash table. */
- if (TREE_CODE (op) == SSA_NAME)
- record_var_is_nonzero (op, block_nonzero_vars_p);
- }
- }
+ if (flag_delete_null_pointer_checks)
+ for (i = 0; i < 2; i++)
+ {
+ tree t = TREE_OPERAND (stmt, i);
+
+ /* Strip away any COMPONENT_REFs. */
+ while (TREE_CODE (t) == COMPONENT_REF)
+ t = TREE_OPERAND (t, 0);
+
+ /* Now see if this is a pointer dereference. */
+ if (TREE_CODE (t) == INDIRECT_REF)
+ {
+ tree op = TREE_OPERAND (t, 0);
+
+ /* If the pointer is a SSA variable, then enter new
+ equivalences into the hash table. */
+ while (TREE_CODE (op) == SSA_NAME)
+ {
+ tree def = SSA_NAME_DEF_STMT (op);
+
+ record_var_is_nonzero (op, block_nonzero_vars_p);
+
+ /* And walk up the USE-DEF chains noting other SSA_NAMEs
+ which are known to have a nonzero value. */
+ if (def
+ && TREE_CODE (def) == MODIFY_EXPR
+ && TREE_CODE (TREE_OPERAND (def, 1)) == NOP_EXPR)
+ op = TREE_OPERAND (TREE_OPERAND (def, 1), 0);
+ else
+ break;
+ }
+ }
+ }
/* A memory store, even an aliased store, creates a useful
equivalence. By exchanging the LHS and RHS, creating suitable