This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] tree-cfg.c: Teach find_taken_edge to reject VAL being NULL.
- From: Kazu Hirata <kazu at cs dot umass dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 03 Nov 2004 23:31:30 -0500 (EST)
- Subject: [patch] tree-cfg.c: Teach find_taken_edge to reject VAL being NULL.
Hi,
Attached is a patch to teach find_taken_edge to reject VAL being NULL.
All callers of find_taken_edge except visit_cond_stmt calls it with
nonzero VAL, so the null checks of VAL are partially redundant.
We always keep COND_EXPR and SWITCH_EXPR "interesting" by removing
degerates forms like those with only one outgoing edge, so it doesn't
make sense to ask find_taken_edge to find the taken edge with no hint,
that is, VAL being NULL.
The patch removes the null checks while having visit_cond_stmt check
its VAL before calling find_taken_edge.
Tested on i686-pc-linux-gnu. OK to apply?
Kazu Hirata
2004-11-04 Kazu Hirata <kazu@cs.umass.edu>
* tree-cfg.c (find_taken_edge): Reject VAL begin NULL.
* tree-ssa-ccp.c (visit_cond_stmt): Don't call find_taken_edge
with VAL being NULL.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.98
diff -u -d -p -r2.98 tree-cfg.c
--- tree-cfg.c 3 Nov 2004 01:40:56 -0000 2.98
+++ tree-cfg.c 3 Nov 2004 02:33:55 -0000
@@ -1954,15 +1954,16 @@ find_taken_edge (basic_block bb, tree va
gcc_assert (stmt);
gcc_assert (is_ctrl_stmt (stmt));
+ gcc_assert (val);
/* If VAL is a predicate of the form N RELOP N, where N is an
SSA_NAME, we can usually determine its truth value. */
- if (val && COMPARISON_CLASS_P (val))
+ if (COMPARISON_CLASS_P (val))
val = fold (val);
/* If VAL is not a constant, we can't determine which edge might
be taken. */
- if (val == NULL || !really_constant_p (val))
+ if (!really_constant_p (val))
return NULL;
if (TREE_CODE (stmt) == COND_EXPR)
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-ccp.c,v
retrieving revision 2.48
diff -u -d -p -r2.48 tree-ssa-ccp.c
--- tree-ssa-ccp.c 27 Oct 2004 17:45:20 -0000 2.48
+++ tree-ssa-ccp.c 3 Nov 2004 02:33:56 -0000
@@ -1123,7 +1123,7 @@ visit_cond_stmt (tree stmt, edge *taken_
to the worklist. If no single edge can be determined statically,
return SSA_PROP_VARYING to feed all the outgoing edges to the
propagation engine. */
- *taken_edge_p = find_taken_edge (block, val.const_val);
+ *taken_edge_p = val.const_val ? find_taken_edge (block, val.const_val) : 0;
if (*taken_edge_p)
return SSA_PROP_INTERESTING;
else