OSDN Git Service

libcpp/
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-loop-manip.c
index f16ec3f..cbd03b7 100644 (file)
@@ -15,8 +15,8 @@ for more details.
    
 You should have received a copy of the GNU General Public License
 along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301, USA.  */
 
 #include "config.h"
 #include "system.h"
@@ -54,6 +54,7 @@ create_iv (tree base, tree step, tree var, struct loop *loop,
   tree stmt, initial, step1, stmts;
   tree vb, va;
   enum tree_code incr_op = PLUS_EXPR;
+  edge pe = loop_preheader_edge (loop);
 
   if (!var)
     {
@@ -74,7 +75,7 @@ create_iv (tree base, tree step, tree var, struct loop *loop,
     {
       if (TYPE_UNSIGNED (TREE_TYPE (step)))
        {
-         step1 = fold (build1 (NEGATE_EXPR, TREE_TYPE (step), step));
+         step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
          if (tree_int_cst_lt (step1, step))
            {
              incr_op = MINUS_EXPR;
@@ -87,11 +88,17 @@ create_iv (tree base, tree step, tree var, struct loop *loop,
              && may_negate_without_overflow_p (step))
            {
              incr_op = MINUS_EXPR;
-             step = fold (build1 (NEGATE_EXPR, TREE_TYPE (step), step));
+             step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
            }
        }
     }
 
+  /* Gimplify the step if necessary.  We put the computations in front of the
+     loop (i.e. the step should be loop invariant).  */
+  step = force_gimple_operand (step, &stmts, true, var);
+  if (stmts)
+    bsi_insert_on_edge_immediate_loop (pe, stmts);
+
   stmt = build2 (MODIFY_EXPR, void_type_node, va,
                 build2 (incr_op, TREE_TYPE (base),
                         vb, step));
@@ -103,11 +110,7 @@ create_iv (tree base, tree step, tree var, struct loop *loop,
 
   initial = force_gimple_operand (base, &stmts, true, var);
   if (stmts)
-    {
-      edge pe = loop_preheader_edge (loop);
-
-      bsi_insert_on_edge_immediate_loop (pe, stmts);
-    }
+    bsi_insert_on_edge_immediate_loop (pe, stmts);
 
   stmt = create_phi_node (vb, loop->header);
   SSA_NAME_DEF_STMT (vb) = stmt;
@@ -563,13 +566,13 @@ copy_phi_node_args (unsigned first_new_block)
   unsigned i;
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
-    BASIC_BLOCK (i)->rbi->duplicated = 1;
+    BASIC_BLOCK (i)->flags |= BB_DUPLICATED;
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
     add_phi_args_after_copy_bb (BASIC_BLOCK (i));
 
   for (i = first_new_block; i < (unsigned) last_basic_block; i++)
-    BASIC_BLOCK (i)->rbi->duplicated = 0;
+    BASIC_BLOCK (i)->flags &= ~BB_DUPLICATED;
 }