c-gimplify.c (gimplify_c_loop): Improve initial implementations for loops whose condi...
authorRoger Sayle <roger@eyesopen.com>
Mon, 6 Dec 2004 17:24:16 +0000 (17:24 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Mon, 6 Dec 2004 17:24:16 +0000 (17:24 +0000)
* c-gimplify.c (gimplify_c_loop): Improve initial implementations
for loops whose conditions are known at compile-time.
* gimplify.c (append_to_statement_list_1): Remove side_effects
parameter, this function should never be called if its false.
(append_to_statement_list): Only call append_to_statement_list_1
if t is non-NULL tree with side-effects.
(append_to_statement_list_force):  Likewise, if t is not NULL.

From-SVN: r91784

gcc/ChangeLog
gcc/c-gimplify.c
gcc/gimplify.c

index 6cc24b7..f5e676e 100644 (file)
@@ -1,3 +1,13 @@
+2004-12-06  Roger Sayle  <roger@eyesopen.com>
+
+       * c-gimplify.c (gimplify_c_loop): Improve initial implementations
+       for loops whose conditions are known at compile-time.
+       * gimplify.c (append_to_statement_list_1): Remove side_effects
+       parameter, this function should never be called if its false.
+       (append_to_statement_list): Only call append_to_statement_list_1
+       if t is non-NULL tree with side-effects.
+       (append_to_statement_list_force):  Likewise, if t is not NULL.
+
 2004-12-06  J"orn Rennecke <joern.rennecke@st.com>
 
        * bt-load.c (btr_def_s): New member own_end;
index d77d75c..db6cd88 100644 (file)
@@ -338,10 +338,23 @@ gimplify_c_loop (tree cond, tree body, tree incr, bool cond_is_first)
   location_t stmt_locus;
 
   stmt_locus = input_location;
+  stmt_list = NULL_TREE;
+  entry = NULL_TREE;
 
-  /* Detect do { ... } while (0) and don't generate loop construct.  */
-  if (!cond_is_first && cond && integer_zerop (cond))
-    top = cond = NULL;
+  break_block = begin_bc_block (bc_break);
+  cont_block = begin_bc_block (bc_continue);
+
+  /* If condition is zero don't generate a loop construct.  */
+  if (cond && integer_zerop (cond))
+    {
+      top = NULL_TREE;
+      exit = NULL_TREE;
+      if (cond_is_first)
+       {
+         t = build_bc_goto (bc_break);
+         append_to_statement_list (t, &stmt_list);
+       }
+    }
   else
     {
       /* If we use a LOOP_EXPR here, we have to feed the whole thing
@@ -349,45 +362,37 @@ gimplify_c_loop (tree cond, tree body, tree incr, bool cond_is_first)
         have to gimplify the loop body NOW so that we can resolve
         break/continue stmts, seems easier to just expand to gotos.  */
       top = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
-    }
-
-  break_block = begin_bc_block (bc_break);
 
-  if (top)
-    {
       /* If we have an exit condition, then we build an IF with gotos either
         out of the loop, or to the top of it.  If there's no exit condition,
         then we just build a jump back to the top.  */
       exit = build_and_jump (&LABEL_EXPR_LABEL (top));
-      if (cond)
+      if (cond && !integer_nonzerop (cond))
        {
          t = build_bc_goto (bc_break);
          exit = build3 (COND_EXPR, void_type_node, cond, exit, t);
          exit = fold (exit);
          gimplify_stmt (&exit);
+
+         if (cond_is_first)
+           {
+             if (incr)
+               {
+                 entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
+                 t = build_and_jump (&LABEL_EXPR_LABEL (entry));
+               }
+             else
+               t = build_bc_goto (bc_continue);
+             append_to_statement_list (t, &stmt_list);
+           }
        }
     }
-  else
-    exit = NULL_TREE;
-
-  cont_block = begin_bc_block (bc_continue);
 
   gimplify_stmt (&body);
   gimplify_stmt (&incr);
 
   body = finish_bc_block (cont_block, body);
 
-  stmt_list = NULL;
-
-  if (cond_is_first && cond)
-    {
-      entry = build1 (LABEL_EXPR, void_type_node, NULL_TREE);
-      t = build_and_jump (&LABEL_EXPR_LABEL (entry));
-      append_to_statement_list (t, &stmt_list);
-    }
-  else
-    entry = NULL_TREE;
-
   append_to_statement_list (top, &stmt_list);
   append_to_statement_list (body, &stmt_list);
   append_to_statement_list (incr, &stmt_list);
index 6a9e3b1..41814a7 100644 (file)
@@ -214,17 +214,14 @@ gimple_pop_condition (tree *pre_p)
     }
 }
 
-/* A subroutine of append_to_statement_list{,_force}.  */
+/* A subroutine of append_to_statement_list{,_force}.  T is not NULL.  */
 
 static void
-append_to_statement_list_1 (tree t, tree *list_p, bool side_effects)
+append_to_statement_list_1 (tree t, tree *list_p)
 {
   tree list = *list_p;
   tree_stmt_iterator i;
 
-  if (!side_effects)
-    return;
-
   if (!list)
     {
       if (t && TREE_CODE (t) == STATEMENT_LIST)
@@ -245,7 +242,8 @@ append_to_statement_list_1 (tree t, tree *list_p, bool side_effects)
 void
 append_to_statement_list (tree t, tree *list_p)
 {
-  append_to_statement_list_1 (t, list_p, t ? TREE_SIDE_EFFECTS (t) : false);
+  if (t && TREE_SIDE_EFFECTS (t))
+    append_to_statement_list_1 (t, list_p);
 }
 
 /* Similar, but the statement is always added, regardless of side effects.  */
@@ -253,7 +251,8 @@ append_to_statement_list (tree t, tree *list_p)
 void
 append_to_statement_list_force (tree t, tree *list_p)
 {
-  append_to_statement_list_1 (t, list_p, t != NULL);
+  if (t != NULL_TREE)
+    append_to_statement_list_1 (t, list_p);
 }
 
 /* Both gimplify the statement T and append it to LIST_P.  */