This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Return an edge if true and false edge of a branch are the same
- From: Steven Bosscher <stevenb at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 15 Feb 2004 17:43:12 +0100
- Subject: [tree-ssa] Return an edge if true and false edge of a branch are the same
- Organization: SUSE Labs
Hi,
When I was working on DCE I noticed that in cleanup_cfg we don't always
remove conditional branches that lead to the same target block.
Bootstrapped&tested on i686-pc-linux-gnu, OK?
Gr.
Steven
* tree-flow.h (cleanup_control_expr_graph): Don't declare here.
* tree-cfg.c (cleanup_control_expr_graph): Make static.
(find_edge_taken_cond_expr): Return an edge if the true and false
edges of a branch lead to the same basic block.
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.267
diff -c -3 -p -r1.1.4.267 tree-cfg.c
*** tree-cfg.c 13 Feb 2004 00:10:25 -0000 1.1.4.267
--- tree-cfg.c 15 Feb 2004 11:29:19 -0000
*************** static void tree_merge_blocks (basic_blo
*** 111,116 ****
--- 111,117 ----
static bool tree_can_merge_blocks_p (basic_block, basic_block);
static void remove_bb (basic_block);
static bool cleanup_control_flow (void);
+ static bool cleanup_control_expr_graph (basic_block, block_stmt_iterator);
static edge find_taken_edge_cond_expr (basic_block, tree);
static edge find_taken_edge_switch_expr (basic_block, tree);
static tree find_case_label_for_value (tree, tree);
*************** cleanup_control_flow (void)
*** 1626,1632 ****
/* Disconnect an unreachable block in the control expression starting
at block BB. */
! bool
cleanup_control_expr_graph (basic_block bb, block_stmt_iterator bsi)
{
edge taken_edge;
--- 1627,1633 ----
/* Disconnect an unreachable block in the control expression starting
at block BB. */
! static bool
cleanup_control_expr_graph (basic_block bb, block_stmt_iterator bsi)
{
edge taken_edge;
*************** find_taken_edge (basic_block bb, tree va
*** 1718,1744 ****
static edge
find_taken_edge_cond_expr (basic_block bb, tree val)
{
! bool always_false;
! bool always_true;
! edge e;
! /* Determine which branch of the if() will be taken. */
! always_false = integer_zerop (val);
! always_true = integer_nonzerop (val);
! /* If VAL is a constant but it can't be reduced to a 0 or a 1, then
we don't really know which edge will be taken at runtime. This
! may happen when comparing addresses (e.g., if (&var1 == 4)) */
! if (!always_false && !always_true)
return NULL;
-
- for (e = bb->succ; e; e = e->succ_next)
- if (((e->flags & EDGE_TRUE_VALUE) && always_true)
- || ((e->flags & EDGE_FALSE_VALUE) && always_false))
- return e;
-
- /* There always should be an edge that is taken. */
- abort ();
}
/* Given a constant value VAL and the entry block BB to a SWITCH_EXPR
--- 1719,1743 ----
static edge
find_taken_edge_cond_expr (basic_block bb, tree val)
{
! edge true_edge, false_edge;
!
! extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
! /* If both edges of the branch lead to the same basic block, it doesn't
! matter which edge is taken. */
! if (true_edge->dest == false_edge->dest)
! return true_edge;
! /* Otherwise, try to determine which branch of the if() will be taken.
! If VAL is a constant but it can't be reduced to a 0 or a 1, then
we don't really know which edge will be taken at runtime. This
! may happen when comparing addresses (e.g., if (&var1 == 4)). */
! if (integer_nonzerop (val))
! return true_edge;
! else if (integer_zerop (val))
! return false_edge;
! else
return NULL;
}
/* Given a constant value VAL and the entry block BB to a SWITCH_EXPR
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.187
diff -c -3 -p -r1.1.4.187 tree-flow.h
*** tree-flow.h 13 Feb 2004 11:15:56 -0000 1.1.4.187
--- tree-flow.h 15 Feb 2004 11:29:20 -0000
*************** extern edge find_taken_edge (basic_block
*** 468,474 ****
extern void cfg_remove_useless_stmts (void);
extern edge thread_edge (edge, basic_block);
extern basic_block label_to_block (tree);
- extern bool cleanup_control_expr_graph (basic_block, block_stmt_iterator);
extern void tree_optimize_tail_calls (bool, enum tree_dump_index);
extern edge tree_block_forwards_to (basic_block bb);
extern void bsi_insert_on_edge (edge, tree);
--- 468,473 ----