This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] lower_cond_expr improvement
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 Nov 2003 23:54:38 -0800
- Subject: [tree-ssa] lower_cond_expr improvement
Creates less garbage for cfgcleanup to clean up.
Tested on i686-linux.
r~
* gimple-low.c (lower_function_body): Lower bind_expr in place.
(lower_stmt): Only incr for stmts we're skipping.
(lower_cond_expr): Detect empty if.
Index: gimple-low.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimple-low.c,v
retrieving revision 1.1.4.7
diff -c -p -d -r1.1.4.7 gimple-low.c
*** gimple-low.c 8 Nov 2003 09:49:19 -0000 1.1.4.7
--- gimple-low.c 11 Nov 2003 07:36:00 -0000
*************** void
*** 57,63 ****
lower_function_body (tree *body)
{
struct lower_data data;
- tree root;
if (TREE_CODE (*body) != BIND_EXPR)
abort ();
--- 57,62 ----
*************** lower_function_body (tree *body)
*** 67,81 ****
BLOCK_CHAIN (data.block) = NULL_TREE;
record_vars (BIND_EXPR_VARS (*body));
! root = BIND_EXPR_BODY (*body);
! lower_stmt_body (&root, &data);
if (data.block != DECL_INITIAL (current_function_decl))
abort ();
! BLOCK_SUBBLOCKS (data.block) =
! blocks_nreverse (BLOCK_SUBBLOCKS (data.block));
!
! *body = root;
}
/* Lowers the EXPR. Unlike gimplification the statements are not relowered
--- 66,78 ----
BLOCK_CHAIN (data.block) = NULL_TREE;
record_vars (BIND_EXPR_VARS (*body));
! *body = BIND_EXPR_BODY (*body);
! lower_stmt_body (body, &data);
if (data.block != DECL_INITIAL (current_function_decl))
abort ();
! BLOCK_SUBBLOCKS (data.block)
! = blocks_nreverse (BLOCK_SUBBLOCKS (data.block));
}
/* Lowers the EXPR. Unlike gimplification the statements are not relowered
*************** lower_stmt (tree_stmt_iterator *tsi, str
*** 104,112 ****
{
case BIND_EXPR:
lower_bind_expr (tsi, data);
! /* Avoid moving the tsi -- it has already been moved by delinking the
! statement. */
! return;
case COMPOUND_EXPR:
abort ();
--- 101,107 ----
{
case BIND_EXPR:
lower_bind_expr (tsi, data);
! break;
case COMPOUND_EXPR:
abort ();
*************** lower_stmt (tree_stmt_iterator *tsi, str
*** 121,126 ****
--- 116,122 ----
case VA_ARG_EXPR:
case RESX_EXPR:
case SWITCH_EXPR:
+ tsi_next (tsi);
break;
case COND_EXPR:
*************** lower_stmt (tree_stmt_iterator *tsi, str
*** 128,138 ****
break;
default:
! print_node_brief (stderr, "", tsi_stmt (*tsi), 0);
abort ();
}
-
- tsi_next (tsi);
}
/* Record the variables in VARS. */
--- 124,132 ----
break;
default:
! print_node_brief (stderr, "", stmt, 0);
abort ();
}
}
/* Record the variables in VARS. */
*************** lower_cond_expr (tree_stmt_iterator *tsi
*** 201,212 ****
{
tree stmt = tsi_stmt (*tsi);
bool then_is_goto, else_is_goto;
! tree then_branch, else_branch, then_label, else_label, end_label;
lower_stmt_body (&COND_EXPR_THEN (stmt), data);
lower_stmt_body (&COND_EXPR_ELSE (stmt), data);
- /* Find out whether the branches are ordinary local gotos. */
then_branch = COND_EXPR_THEN (stmt);
else_branch = COND_EXPR_ELSE (stmt);
--- 195,205 ----
{
tree stmt = tsi_stmt (*tsi);
bool then_is_goto, else_is_goto;
! tree then_branch, else_branch, then_label, else_label, end_label, t;
lower_stmt_body (&COND_EXPR_THEN (stmt), data);
lower_stmt_body (&COND_EXPR_ELSE (stmt), data);
then_branch = COND_EXPR_THEN (stmt);
else_branch = COND_EXPR_ELSE (stmt);
*************** lower_cond_expr (tree_stmt_iterator *tsi
*** 214,239 ****
else_is_goto = simple_goto_p (else_branch);
if (then_is_goto && else_is_goto)
! return;
/* Replace the cond_expr with explicit gotos. */
if (!then_is_goto)
{
! then_label = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
! COND_EXPR_THEN (stmt) = build_and_jump (&LABEL_EXPR_LABEL (then_label));
}
- else
- then_label = NULL_TREE;
if (!else_is_goto)
{
! else_label = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
! COND_EXPR_ELSE (stmt) = build_and_jump (&LABEL_EXPR_LABEL (else_label));
}
- else
- else_label = NULL_TREE;
- end_label = NULL_TREE;
if (then_label)
{
tsi_link_after (tsi, then_label, TSI_CONTINUE_LINKING);
--- 207,255 ----
else_is_goto = simple_goto_p (else_branch);
if (then_is_goto && else_is_goto)
! {
! tsi_next (tsi);
! return;
! }
!
! then_label = NULL_TREE;
! else_label = NULL_TREE;
! end_label = NULL_TREE;
/* Replace the cond_expr with explicit gotos. */
if (!then_is_goto)
{
! t = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
! if (TREE_SIDE_EFFECTS (then_branch))
! then_label = t;
! else
! end_label = t;
! COND_EXPR_THEN (stmt) = build_and_jump (&LABEL_EXPR_LABEL (t));
}
if (!else_is_goto)
{
! t = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
! if (TREE_SIDE_EFFECTS (else_branch))
! else_label = t;
! else
! {
! /* Both THEN and ELSE can be no-ops if one or both contained an
! empty BIND_EXPR that was associated with the toplevel block
! of an inlined function. In that case remove_useless_stmts
! can't have cleaned things up for us; kill the whole
! conditional now. */
! if (end_label)
! {
! tsi_delink (tsi);
! return;
! }
! else
! end_label = t;
! }
! COND_EXPR_ELSE (stmt) = build_and_jump (&LABEL_EXPR_LABEL (t));
}
if (then_label)
{
tsi_link_after (tsi, then_label, TSI_CONTINUE_LINKING);
*************** lower_cond_expr (tree_stmt_iterator *tsi
*** 255,260 ****
--- 271,277 ----
if (end_label)
tsi_link_after (tsi, end_label, TSI_CONTINUE_LINKING);
+ tsi_next (tsi);
}
/* Expand those variables in the unexpanded_var_list that are used. */