This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Re: [tree-ssa] doloop problems


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;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]