+2012-08-07  Richard Guenther  <rguenther@suse.de>
+
+       * tree-flow.h (copy_ssa_name_fn): New function.
+       (duplicate_ssa_name_fn): Likewise.
+       * tree-flow-inline.h (copy_ssa_name): New function.
+       (duplicate_ssa_name): Likewise.
+       * tree-ssanames.c (copy_ssa_name_fn): New function.
+       (duplicate_ssa_name): Rename to ...
+       (duplicate_ssa_name_fn): ... this and adjust.
+       * tree-tailcall.c (update_accumulator_with_ops): Use copy_ssa_name.
+       * tree-vect-loop-manip.c (slpeel_update_phi_nodes_for_guard1): Likewise.
+       (slpeel_update_phi_nodes_for_guard2): Likewise.
+       (slpeel_tree_peel_loop_to_edge): Likewise.
+       (vect_loop_versioning): Likewise.
+       * tree-parloops.c (transform_to_exit_first_loop): Likewise.
+       (create_parallel_loop): Likewise.
+       * ipa-split.c (split_function): Likewise.
+       * tree-vect-loop.c (vect_is_simple_reduction_1): Likewise.
+       (vect_create_epilog_for_reduction): Likewise.
+       * tree-vect-data-refs.c (bump_vector_ptr): Likewise.
+       (vect_setup_realignment): Likewise.
+       * tree-vect-stmts.c (vectorizable_load): Likewise.
+       * tree-switch-conversion.c (build_one_array): Likewise.
+       (gen_def_assigns): Likewise.
+       * tree-cfg.c (gimple_make_forwarder_block): Likewise.
+       * graphite-sese-to-poly.c (rewrite_close_phi_out_of_ssa): Call
+       create_zero_dim_array with the SSA name.
+       (rewrite_phi_out_of_ssa): Likewise.
+       (rewrite_cross_bb_scalar_dependence): Likewise.  Use copy_ssa_name.
+
 2012-08-07  Richard Guenther  <rguenther@suse.de>
 
        * tree-dfa.c (set_ssa_default_def): Clear the SSA_NAME_DEFAULT_DEF
 
   sese region = SCOP_REGION (scop);
   gimple phi = gsi_stmt (*psi);
   tree res = gimple_phi_result (phi);
-  tree var = SSA_NAME_VAR (res);
   basic_block bb = gimple_bb (phi);
   gimple_stmt_iterator gsi = gsi_after_labels (bb);
   tree arg = gimple_phi_arg_def (phi, 0);
     }
   else
     {
-      tree zero_dim_array = create_zero_dim_array (var, "Close_Phi");
+      tree zero_dim_array = create_zero_dim_array (res, "Close_Phi");
 
       stmt = gimple_build_assign (res, zero_dim_array);
 
   gimple phi = gsi_stmt (*psi);
   basic_block bb = gimple_bb (phi);
   tree res = gimple_phi_result (phi);
-  tree var = SSA_NAME_VAR (res);
-  tree zero_dim_array = create_zero_dim_array (var, "phi_out_of_ssa");
+  tree var;
+  tree zero_dim_array = create_zero_dim_array (res, "phi_out_of_ssa");
   gimple stmt;
   gimple_seq stmts;
 
 rewrite_cross_bb_scalar_dependence (scop_p scop, tree zero_dim_array,
                                    tree def, gimple use_stmt)
 {
-  tree var = SSA_NAME_VAR (def);
-  gimple name_stmt = gimple_build_assign (var, zero_dim_array);
-  tree name = make_ssa_name (var, name_stmt);
+  gimple name_stmt;
+  tree name;
   ssa_op_iter iter;
   use_operand_p use_p;
 
   gcc_assert (gimple_code (use_stmt) != GIMPLE_PHI);
 
+  name = copy_ssa_name (def, NULL);
+  name_stmt = gimple_build_assign (name, zero_dim_array);
+
   gimple_assign_set_lhs (name_stmt, name);
   insert_stmts (scop, name_stmt, NULL, gsi_for_stmt (use_stmt));
 
        if (!zero_dim_array)
          {
            zero_dim_array = create_zero_dim_array
-             (SSA_NAME_VAR (def), "Cross_BB_scalar_dependence");
+             (def, "Cross_BB_scalar_dependence");
            insert_out_of_ssa_copy (scop, zero_dim_array, def,
                                    SSA_NAME_DEF_STMT (def));
            gsi_next (gsi);
 
              if (TREE_CODE (retval) == SSA_NAME
                  && !DECL_BY_REFERENCE (DECL_RESULT (current_function_decl)))
                {
-                 retval = make_ssa_name (SSA_NAME_VAR (retval), call);
+                 retval = copy_ssa_name (retval, call);
 
                  /* See if there is PHI defining return value.  */
                  for (psi = gsi_start_phis (return_bb);
 
       phi = gsi_stmt (gsi);
       var = gimple_phi_result (phi);
       new_phi = create_phi_node (var, bb);
-      gimple_phi_set_result (phi, make_ssa_name (SSA_NAME_VAR (var), phi));
+      gimple_phi_set_result (phi, copy_ssa_name (var, phi));
       add_phi_arg (new_phi, gimple_phi_result (phi), fallthru,
                   UNKNOWN_LOCATION);
     }
 
   return make_ssa_name_fn (cfun, var, stmt);
 }
 
+/* Return an SSA_NAME node using the template SSA name NAME defined in
+   statement STMT in function cfun.  */
+
+static inline tree
+copy_ssa_name (tree var, gimple stmt)
+{
+  return copy_ssa_name_fn (cfun, var, stmt);
+}
+
+/*  Creates a duplicate of a SSA name NAME tobe defined by statement STMT
+    in function cfun.  */
+
+static inline tree
+duplicate_ssa_name (tree var, gimple stmt)
+{
+  return duplicate_ssa_name_fn (cfun, var, stmt);
+}
+
+
 /* Returns the base object and a constant BITS_PER_UNIT offset in *POFFSET that
    denotes the starting address of the memory access EXP.
    Returns NULL_TREE if the offset is not constant or any component
 
 extern void init_ssanames (struct function *, int);
 extern void fini_ssanames (void);
 extern tree make_ssa_name_fn (struct function *, tree, gimple);
-extern tree duplicate_ssa_name (tree, gimple);
+extern tree copy_ssa_name_fn (struct function *, tree, gimple);
+extern tree duplicate_ssa_name_fn (struct function *, tree, gimple);
 extern void duplicate_ssa_name_ptr_info (tree, struct ptr_info_def *);
 extern void release_ssa_name (tree);
 extern void release_defs (gimple);
 
     {
       phi = gsi_stmt (gsi);
       res = PHI_RESULT (phi);
-      t = make_ssa_name (SSA_NAME_VAR (res), phi);
+      t = copy_ssa_name (res, phi);
       SET_PHI_RESULT (phi, t);
       nphi = create_phi_node (res, orig_header);
       add_phi_arg (nphi, t, hpred, UNKNOWN_LOCATION);
   cvar_base = SSA_NAME_VAR (cvar);
   phi = SSA_NAME_DEF_STMT (cvar);
   cvar_init = PHI_ARG_DEF_FROM_EDGE (phi, loop_preheader_edge (loop));
-  initvar = make_ssa_name (cvar_base, NULL);
+  initvar = copy_ssa_name (cvar, NULL);
   SET_USE (PHI_ARG_DEF_PTR_FROM_EDGE (phi, loop_preheader_edge (loop)),
           initvar);
   cvar_next = PHI_ARG_DEF_FROM_EDGE (phi, loop_latch_edge (loop));
 
   return pi;
 }
 
+
+/* Creates a new SSA name using the template NAME tobe defined by
+   statement STMT in function FN.  */
+
+tree
+copy_ssa_name_fn (struct function *fn, tree name, gimple stmt)
+{
+  return make_ssa_name_fn (fn, SSA_NAME_VAR (name), stmt);
+}
+
+
 /* Creates a duplicate of the ptr_info_def at PTR_INFO for use by
    the SSA name NAME.  */
 
 }
 
 
-/* Creates a duplicate of a ssa name NAME tobe defined by statement STMT.  */
+/* Creates a duplicate of a ssa name NAME tobe defined by statement STMT
+   in function FN.  */
 
 tree
-duplicate_ssa_name (tree name, gimple stmt)
+duplicate_ssa_name_fn (struct function *fn, tree name, gimple stmt)
 {
-  tree new_name = make_ssa_name (SSA_NAME_VAR (name), stmt);
+  tree new_name = copy_ssa_name_fn (fn, name, stmt);
   struct ptr_info_def *old_ptr_info = SSA_NAME_PTR_INFO (name);
 
   if (old_ptr_info)
 
 
   gcc_assert (info->default_values[num]);
 
-  name = make_ssa_name (SSA_NAME_VAR (PHI_RESULT (phi)), NULL);
+  name = copy_ssa_name (PHI_RESULT (phi), NULL);
   info->target_inbound_names[num] = name;
 
   cst = constructor_contains_same_values_p (info->constructors[num]);
       load = gimple_build_assign (name, fetch);
     }
 
-  SSA_NAME_DEF_STMT (name) = load;
   gsi_insert_before (&gsi, load, GSI_SAME_STMT);
   update_stmt (load);
   info->arr_ref_last = load;
 
   for (i = 0; i < info->phi_count; i++)
     {
-      tree name
-       = make_ssa_name (SSA_NAME_VAR (info->target_inbound_names[i]), NULL);
-
+      tree name = copy_ssa_name (info->target_inbound_names[i], NULL);
       info->target_outbound_names[i] = name;
       assign = gimple_build_assign (name, info->default_values[i]);
-      SSA_NAME_DEF_STMT (name) = assign;
       gsi_insert_before (gsi, assign, GSI_SAME_STMT);
       update_stmt (assign);
     }
 
                             gimple_stmt_iterator gsi)
 {
   gimple stmt;
-  tree var;
+  tree var = copy_ssa_name (acc, NULL);
   if (types_compatible_p (TREE_TYPE (acc), TREE_TYPE (op1)))
-    stmt = gimple_build_assign_with_ops (code, SSA_NAME_VAR (acc), acc, op1);
+    stmt = gimple_build_assign_with_ops (code, var, acc, op1);
   else
     {
       tree rhs = fold_convert (TREE_TYPE (acc),
                                            op1));
       rhs = force_gimple_operand_gsi (&gsi, rhs,
                                      false, NULL, false, GSI_CONTINUE_LINKING);
-      stmt = gimple_build_assign (NULL_TREE, rhs);
+      stmt = gimple_build_assign (var, rhs);
     }
-  var = make_ssa_name (SSA_NAME_VAR (acc), stmt);
-  gimple_assign_set_lhs (stmt, var);
-  update_stmt (stmt);
   gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
   return var;
 }
 
   stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
   struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
   tree vectype = STMT_VINFO_VECTYPE (stmt_info);
-  tree ptr_var = SSA_NAME_VAR (dataref_ptr);
   tree update = TYPE_SIZE_UNIT (vectype);
   gimple incr_stmt;
   ssa_op_iter iter;
   if (bump)
     update = bump;
 
-  incr_stmt = gimple_build_assign_with_ops (POINTER_PLUS_EXPR, ptr_var,
+  new_dataref_ptr = copy_ssa_name (dataref_ptr, NULL);
+  incr_stmt = gimple_build_assign_with_ops (POINTER_PLUS_EXPR, new_dataref_ptr,
                                            dataref_ptr, update);
-  new_dataref_ptr = make_ssa_name (ptr_var, incr_stmt);
-  gimple_assign_set_lhs (incr_stmt, new_dataref_ptr);
   vect_finish_stmt_generation (stmt, incr_stmt, gsi);
 
   /* Copy the points-to information if it exists. */
       ptr = vect_create_data_ref_ptr (stmt, vectype, loop_for_initial_load,
                                      NULL_TREE, &init_addr, NULL, &inc,
                                      true, &inv_p);
+      new_temp = copy_ssa_name (ptr, NULL);
       new_stmt = gimple_build_assign_with_ops
-                  (BIT_AND_EXPR, NULL_TREE, ptr,
+                  (BIT_AND_EXPR, new_temp, ptr,
                    build_int_cst (TREE_TYPE (ptr),
                                   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
-      new_temp = make_ssa_name (SSA_NAME_VAR (ptr), new_stmt);
-      gimple_assign_set_lhs (new_stmt, new_temp);
       new_bb = gsi_insert_on_edge_immediate (pe, new_stmt);
       gcc_assert (!new_bb);
       data_ref
 
        gsi_next (&gsi_orig), gsi_next (&gsi_update))
     {
       source_location loop_locus, guard_locus;
+      tree new_res;
       orig_phi = gsi_stmt (gsi_orig);
       update_phi = gsi_stmt (gsi_update);
 
       /** 1. Handle new-merge-point phis  **/
 
       /* 1.1. Generate new phi node in NEW_MERGE_BB:  */
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 new_merge_bb);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, new_merge_bb);
 
       /* 1.2. NEW_MERGE_BB has two incoming edges: GUARD_EDGE and the exit-edge
             of LOOP. Set the two phi args in NEW_PHI for these edges:  */
        continue;
 
       /* 2.1. Generate new phi node in NEW_EXIT_BB:  */
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 *new_exit_bb);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, *new_exit_bb);
 
       /* 2.2. NEW_EXIT_BB has one incoming edge: the exit-edge of the loop.  */
       add_phi_arg (new_phi, loop_arg, single_exit (loop), loop_locus);
 
   for (gsi = gsi_start_phis (update_bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
+      tree new_res;
       update_phi = gsi_stmt (gsi);
       orig_phi = update_phi;
       orig_def = PHI_ARG_DEF_FROM_EDGE (orig_phi, e);
       /** 1. Handle new-merge-point phis  **/
 
       /* 1.1. Generate new phi node in NEW_MERGE_BB:  */
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 new_merge_bb);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, new_merge_bb);
 
       /* 1.2. NEW_MERGE_BB has two incoming edges: GUARD_EDGE and the exit-edge
             of LOOP. Set the two PHI args in NEW_PHI for these edges:  */
       /** 2. Handle loop-closed-ssa-form phis  **/
 
       /* 2.1. Generate new phi node in NEW_EXIT_BB:  */
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 *new_exit_bb);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, *new_exit_bb);
 
       /* 2.2. NEW_EXIT_BB has one incoming edge: the exit-edge of the loop.  */
       add_phi_arg (new_phi, loop_arg, single_exit (loop), UNKNOWN_LOCATION);
       arg = guard_arg;
 
       /* 3.2. Generate new phi node in GUARD_BB:  */
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 guard_edge->src);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, guard_edge->src);
 
       /* 3.3. GUARD_BB has one incoming edge:  */
       gcc_assert (EDGE_COUNT (guard_edge->src->preds) == 1);
            break;
        if (gsi_end_p (gsi))
          {
-           gimple new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (phi)),
-                                             exit_e->dest);
+           tree new_vop = copy_ssa_name (PHI_RESULT (phi), NULL);
+           gimple new_phi = create_phi_node (new_vop, exit_e->dest);
            tree vop = PHI_ARG_DEF_FROM_EDGE (phi, EDGE_SUCC (loop->latch, 0));
            imm_use_iterator imm_iter;
            gimple stmt;
-           tree new_vop = make_ssa_name (SSA_NAME_VAR (PHI_RESULT (phi)),
-                                         new_phi);
            use_operand_p use_p;
 
            add_phi_arg (new_phi, vop, exit_e, UNKNOWN_LOCATION);
 
   for (gsi = gsi_start_phis (merge_bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
+      tree new_res;
       orig_phi = gsi_stmt (gsi);
-      new_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (orig_phi)),
-                                 new_exit_bb);
+      new_res = copy_ssa_name (PHI_RESULT (orig_phi), NULL);
+      new_phi = create_phi_node (new_res, new_exit_bb);
       arg = PHI_ARG_DEF_FROM_EDGE (orig_phi, e);
       add_phi_arg (new_phi, arg, new_exit_e,
                   gimple_phi_arg_location_from_edge (orig_phi, e));
 
   if (orig_code == MINUS_EXPR)
     {
       tree rhs = gimple_assign_rhs2 (def_stmt);
-      tree negrhs = make_ssa_name (SSA_NAME_VAR (rhs), NULL);
+      tree negrhs = copy_ssa_name (rhs, NULL);
       gimple negate_stmt = gimple_build_assign_with_ops (NEGATE_EXPR, negrhs,
                                                         rhs, NULL);
       gimple_stmt_iterator gsi = gsi_for_stmt (def_stmt);
     {
       for (j = 0; j < ncopies; j++)
         {
-          phi = create_phi_node (SSA_NAME_VAR (def), exit_bb);
+         tree new_def = copy_ssa_name (def, NULL);
+          phi = create_phi_node (new_def, exit_bb);
           set_vinfo_for_stmt (phi, new_stmt_vec_info (phi, loop_vinfo, NULL));
           if (j == 0)
             VEC_quick_push (gimple, new_phis, phi);
       inner_phis = VEC_alloc (gimple, heap, VEC_length (tree, vect_defs));
       FOR_EACH_VEC_ELT (gimple, new_phis, i, phi)
        {
-         gimple outer_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (phi)),
-                                             exit_bb);
+         tree new_result = copy_ssa_name (PHI_RESULT (phi), NULL);
+         gimple outer_phi = create_phi_node (new_result, exit_bb);
          SET_PHI_ARG_DEF (outer_phi, single_exit (loop)->dest_idx,
                           PHI_RESULT (phi));
          set_vinfo_for_stmt (outer_phi, new_stmt_vec_info (outer_phi,
           while (STMT_VINFO_RELATED_STMT (vinfo_for_stmt (phi)))
             {
              phi = STMT_VINFO_RELATED_STMT (vinfo_for_stmt (phi));
-             outer_phi = create_phi_node (SSA_NAME_VAR (PHI_RESULT (phi)),
-                                          exit_bb);
+             new_result = copy_ssa_name (PHI_RESULT (phi), NULL);
+             outer_phi = create_phi_node (new_result, exit_bb);
              SET_PHI_ARG_DEF (outer_phi, single_exit (loop)->dest_idx,
                               PHI_RESULT (phi));
              set_vinfo_for_stmt (outer_phi, new_stmt_vec_info (outer_phi,
 
                                                 NULL_TREE, true,
                                                 GSI_SAME_STMT);
              CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, newref);
-             newoff = SSA_NAME_VAR (running_off);
+             newoff = copy_ssa_name (running_off, NULL);
              if (POINTER_TYPE_P (TREE_TYPE (newoff)))
                incr = gimple_build_assign_with_ops (POINTER_PLUS_EXPR, newoff,
                                                     running_off, stride_step);
              else
                incr = gimple_build_assign_with_ops (PLUS_EXPR, newoff,
                                                     running_off, stride_step);
-             newoff = make_ssa_name (newoff, incr);
-             gimple_assign_set_lhs (incr, newoff);
              vect_finish_stmt_generation (stmt, incr, gsi);
 
              running_off = newoff;
                                                    dr_explicit_realign,
                                                    dataref_ptr, NULL);
 
+                   ptr = copy_ssa_name (dataref_ptr, NULL);
                    new_stmt = gimple_build_assign_with_ops
-                                (BIT_AND_EXPR, NULL_TREE, dataref_ptr,
+                                (BIT_AND_EXPR, ptr, dataref_ptr,
                                  build_int_cst
                                  (TREE_TYPE (dataref_ptr),
                                   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
-                   ptr = make_ssa_name (SSA_NAME_VAR (dataref_ptr), new_stmt);
-                   gimple_assign_set_lhs (new_stmt, ptr);
                    vect_finish_stmt_generation (stmt, new_stmt, gsi);
                    data_ref
                      = build2 (MEM_REF, vectype, ptr,
                                  build_int_cst
                                  (TREE_TYPE (ptr),
                                   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
-                   ptr = make_ssa_name (SSA_NAME_VAR (dataref_ptr), new_stmt);
+                   ptr = copy_ssa_name (dataref_ptr, new_stmt);
                    gimple_assign_set_lhs (new_stmt, ptr);
                    vect_finish_stmt_generation (stmt, new_stmt, gsi);
                    data_ref
                    break;
                  }
                case dr_explicit_realign_optimized:
+                 new_temp = copy_ssa_name (dataref_ptr, NULL);
                  new_stmt = gimple_build_assign_with_ops
-                              (BIT_AND_EXPR, NULL_TREE, dataref_ptr,
+                              (BIT_AND_EXPR, new_temp, dataref_ptr,
                                build_int_cst
                                  (TREE_TYPE (dataref_ptr),
                                   -(HOST_WIDE_INT)TYPE_ALIGN_UNIT (vectype)));
-                 new_temp = make_ssa_name (SSA_NAME_VAR (dataref_ptr),
-                                           new_stmt);
-                 gimple_assign_set_lhs (new_stmt, new_temp);
                  vect_finish_stmt_generation (stmt, new_stmt, gsi);
                  data_ref
                    = build2 (MEM_REF, vectype, new_temp,