OSDN Git Service

PR c++/43016
[pf3gnuchains/gcc-fork.git] / gcc / tree-loop-distribution.c
index 3c93f8e..746e442 100644 (file)
@@ -1,5 +1,6 @@
 /* Loop distribution.
-   Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
    Contributed by Georges-Andre Silber <Georges-Andre.Silber@ensmp.fr>
    and Sebastian Pop <sebastian.pop@amd.com>.
 
@@ -45,11 +46,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "system.h"
 #include "coretypes.h"
 #include "tm.h"
-#include "ggc.h"
 #include "tree.h"
-#include "target.h"
-
-#include "rtl.h"
 #include "basic-block.h"
 #include "diagnostic.h"
 #include "tree-flow.h"
@@ -118,8 +115,8 @@ update_phis_for_loop_copy (struct loop *orig_loop, struct loop *new_loop)
 
          if (!new_ssa_name)
            /* This only happens if there are no definitions inside the
-              loop.  Use the phi_result in this case.  */
-           new_ssa_name = PHI_RESULT (phi_new);
+              loop.  Use the the invariant in the new loop as is.  */
+           new_ssa_name = def;
        }
       else
        /* Could be an integer.  */
@@ -222,19 +219,17 @@ generate_loops_for_partition (struct loop *loop, bitmap partition, bool copy_p)
 /* Build the size argument for a memset call.  */
 
 static inline tree
-build_size_arg_loc (location_t loc, tree nb_iter, tree op, gimple_seq* stmt_list)
+build_size_arg_loc (location_t loc, tree nb_iter, tree op,
+                   gimple_seq *stmt_list)
 {
-    tree nb_bytes;
-    gimple_seq stmts = NULL;
-
-    nb_bytes = fold_build2_loc (loc, MULT_EXPR, size_type_node,
-                           fold_convert_loc (loc, size_type_node, nb_iter),
-                           fold_convert_loc (loc, size_type_node,
-                                             TYPE_SIZE_UNIT (TREE_TYPE (op))));
-    nb_bytes = force_gimple_operand (nb_bytes, &stmts, true, NULL);
-    gimple_seq_add_seq (stmt_list, stmts);
-
-    return nb_bytes;
+  gimple_seq stmts;
+  tree x = size_binop_loc (loc, MULT_EXPR,
+                          fold_convert_loc (loc, sizetype, nb_iter),
+                          TYPE_SIZE_UNIT (TREE_TYPE (op)));
+  x = force_gimple_operand (x, &stmts, true, NULL);
+  gimple_seq_add_seq (stmt_list, stmts);
+
+  return x;
 }
 
 /* Generate a call to memset.  Return true when the operation succeeded.  */
@@ -243,12 +238,11 @@ static bool
 generate_memset_zero (gimple stmt, tree op0, tree nb_iter,
                      gimple_stmt_iterator bsi)
 {
-  tree addr_base;
-  tree nb_bytes = NULL;
+  tree addr_base, nb_bytes;
   bool res = false;
-  gimple_seq stmts = NULL, stmt_list = NULL;
+  gimple_seq stmt_list = NULL, stmts;
   gimple fn_call;
-  tree mem, fndecl, fntype, fn;
+  tree mem, fn;
   gimple_stmt_iterator i;
   struct data_reference *dr = XCNEW (struct data_reference);
   location_t loc = gimple_location (stmt);
@@ -259,34 +253,37 @@ generate_memset_zero (gimple stmt, tree op0, tree nb_iter,
     goto end;
 
   /* Test for a positive stride, iterating over every element.  */
-  if (integer_zerop (fold_build2_loc (loc,
-                                 MINUS_EXPR, integer_type_node, DR_STEP (dr),
-                                 TYPE_SIZE_UNIT (TREE_TYPE (op0)))))
+  if (integer_zerop (size_binop (MINUS_EXPR,
+                                fold_convert (sizetype, DR_STEP (dr)),
+                                TYPE_SIZE_UNIT (TREE_TYPE (op0)))))
     {
-      tree offset = fold_convert_loc (loc, sizetype,
-                                     size_binop_loc (loc, PLUS_EXPR,
-                                                     DR_OFFSET (dr),
-                                                     DR_INIT (dr)));
+      addr_base = fold_convert_loc (loc, sizetype,
+                                   size_binop_loc (loc, PLUS_EXPR,
+                                                   DR_OFFSET (dr),
+                                                   DR_INIT (dr)));
       addr_base = fold_build2_loc (loc, POINTER_PLUS_EXPR,
-                              TREE_TYPE (DR_BASE_ADDRESS (dr)),
-                              DR_BASE_ADDRESS (dr), offset);
+                                  TREE_TYPE (DR_BASE_ADDRESS (dr)),
+                                  DR_BASE_ADDRESS (dr), addr_base);
+
+      nb_bytes = build_size_arg_loc (loc, nb_iter, op0, &stmt_list);
     }
 
   /* Test for a negative stride, iterating over every element.  */
-  else if (integer_zerop (fold_build2_loc (loc, PLUS_EXPR, integer_type_node,
-                                      TYPE_SIZE_UNIT (TREE_TYPE (op0)),
-                                      DR_STEP (dr))))
+  else if (integer_zerop (size_binop (PLUS_EXPR,
+                                     TYPE_SIZE_UNIT (TREE_TYPE (op0)),
+                                     fold_convert (sizetype, DR_STEP (dr)))))
     {
       nb_bytes = build_size_arg_loc (loc, nb_iter, op0, &stmt_list);
-      addr_base = size_binop_loc (loc, PLUS_EXPR, DR_OFFSET (dr), DR_INIT (dr));
-      addr_base = fold_build2_loc (loc, MINUS_EXPR, sizetype, addr_base,
-                              fold_convert_loc (loc, sizetype, nb_bytes));
-      addr_base = force_gimple_operand (addr_base, &stmts, true, NULL);
-      gimple_seq_add_seq (&stmt_list, stmts);
 
+      addr_base = size_binop_loc (loc, PLUS_EXPR, DR_OFFSET (dr), DR_INIT (dr));
+      addr_base = fold_convert_loc (loc, sizetype, addr_base);
+      addr_base = size_binop_loc (loc, MINUS_EXPR, addr_base,
+                                 fold_convert_loc (loc, sizetype, nb_bytes));
+      addr_base = size_binop_loc (loc, PLUS_EXPR, addr_base,
+                                 TYPE_SIZE_UNIT (TREE_TYPE (op0)));
       addr_base = fold_build2_loc (loc, POINTER_PLUS_EXPR,
-                              TREE_TYPE (DR_BASE_ADDRESS (dr)),
-                              DR_BASE_ADDRESS (dr), addr_base);
+                                  TREE_TYPE (DR_BASE_ADDRESS (dr)),
+                                  DR_BASE_ADDRESS (dr), addr_base);
     }
   else
     goto end;
@@ -294,12 +291,7 @@ generate_memset_zero (gimple stmt, tree op0, tree nb_iter,
   mem = force_gimple_operand (addr_base, &stmts, true, NULL);
   gimple_seq_add_seq (&stmt_list, stmts);
 
-  fndecl = implicit_built_in_decls [BUILT_IN_MEMSET];
-  fntype = TREE_TYPE (fndecl);
-  fn = build1 (ADDR_EXPR, build_pointer_type (fntype), fndecl);
-
-  if (!nb_bytes)
-    nb_bytes = build_size_arg_loc (loc, nb_iter, op0, &stmt_list);
+  fn = build_fold_addr_expr (implicit_built_in_decls [BUILT_IN_MEMSET]);
   fn_call = gimple_build_call (fn, 3, mem, integer_zero_node, nb_bytes);
   gimple_seq_add_stmt (&stmt_list, fn_call);
 
@@ -393,6 +385,8 @@ generate_builtin (struct loop *loop, bitmap partition, bool copy_p)
                goto end;
 
              write = stmt;
+             if (bb == loop->latch)
+               nb_iter = number_of_latch_executions (loop);
            }
        }
     }
@@ -1124,7 +1118,7 @@ ldist_gen (struct loop *loop, struct graph *rdg,
 static int
 distribute_loop (struct loop *loop, VEC (gimple, heap) *stmts)
 {
-  bool res = false;
+  int res = 0;
   struct graph *rdg;
   gimple s;
   unsigned i;
@@ -1242,6 +1236,6 @@ struct gimple_opt_pass pass_loop_distribution =
   0,                           /* properties_provided */
   0,                           /* properties_destroyed */
   0,                           /* todo_flags_start */
-  TODO_dump_func | TODO_verify_loops            /* todo_flags_finish */
+  TODO_dump_func                /* todo_flags_finish */
  }
 };