This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Re: [tree-ssa] doloop problems
- From: Jason Merrill <jason at redhat dot com>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 16 Jun 2003 15:29:18 -0400
- Subject: Re: [PATCH] Re: [tree-ssa] doloop problems
- References: <31F24FF4-9FB8-11D7-8FE9-000393A6D2F2@physics.uc.edu>
Here's a patch I wrote a while back to do the same thing. I didn't check
it in because of concern about code growth. What do others think?
*** c-simplify.c.~1~ 2003-05-23 17:24:44.000000000 -0400
--- c-simplify.c 2003-05-23 19:09:50.000000000 -0400
*************** build_bc_goto (bc)
*** 585,591 ****
controlled by the loop. INCR is the increment expression of a for-loop,
or NULL_TREE. COND_IS_FIRST indicates whether the condition is
evaluated before the loop body as in while and for loops, or after the
! loop body as in do-while loops. */
static tree
simplify_c_loop (cond, body, incr, cond_is_first)
--- 585,597 ----
controlled by the loop. INCR is the increment expression of a for-loop,
or NULL_TREE. COND_IS_FIRST indicates whether the condition is
evaluated before the loop body as in while and for loops, or after the
! loop body as in do-while loops. Note that this function evaluates the
! condition at the end in both cases, and also wraps the loop in the test
! in the first case, so:
!
! while (i < 3) { ... }
! becomes
! if (i < 3) while (1) { ...; if (i < 3); else break; } */
static tree
simplify_c_loop (cond, body, incr, cond_is_first)
*************** simplify_c_loop (cond, body, incr, cond_
*** 604,611 ****
break_block = begin_bc_block (bc_break);
- loop = build (LOOP_EXPR, void_type_node, NULL_TREE);
-
if (cond)
{
simplify_condition (&cond);
--- 610,615 ----
*************** simplify_c_loop (cond, body, incr, cond_
*** 623,646 ****
body = finish_bc_block (cont_block, body);
stuff = NULL_TREE;
- if (cond_is_first)
- {
- add_tree (exit, &stuff);
- add_tree (body, &stuff);
- add_tree (incr, &stuff);
- }
- else
- {
- add_tree (body, &stuff);
- add_tree (incr, &stuff);
- add_tree (exit, &stuff);
- }
! annotate_all_with_file_line (&stuff, stmt_filename, stmt_lineno);
! LOOP_EXPR_BODY (loop) = rationalize_compound_expr (stuff);
loop = finish_bc_block (break_block, loop);
return loop;
}
--- 627,644 ----
body = finish_bc_block (cont_block, body);
stuff = NULL_TREE;
! add_tree (body, &stuff);
! add_tree (incr, &stuff);
! add_tree (exit, &stuff);
! annotate_all_with_file_line (&stuff, stmt_filename, stmt_lineno);
+ loop = build (LOOP_EXPR, void_type_node, stuff);
loop = finish_bc_block (break_block, loop);
+ if (cond_is_first && cond)
+ loop = build (COND_EXPR, void_type_node, unshare_expr (cond),
+ loop, build_empty_stmt ());
return loop;
}