[auto-inc-dec.c] Account for cost of move operation in FORM_PRE_ADD and FORM_POST_ADD...
authorktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 26 Oct 2015 11:51:47 +0000 (11:51 +0000)
committerktkachov <ktkachov@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 26 Oct 2015 11:51:47 +0000 (11:51 +0000)
* auto-inc-dec.c (insert_move_insn_before): Delete.
(attempt_change): Remember to cost the simple move in the
FORM_PRE_ADD and FORM_POST_ADD cases.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229344 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/auto-inc-dec.c

index 7cb539f..69d2ccb 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-26  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
+
+       * auto-inc-dec.c (insert_move_insn_before): Delete.
+       (attempt_change): Remember to cost the simple move in the
+       FORM_PRE_ADD and FORM_POST_ADD cases.
+
 2015-10-26  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        PR target/68091
index e003b13..9f7c8e0 100644 (file)
@@ -439,24 +439,6 @@ move_dead_notes (rtx_insn *to_insn, rtx_insn *from_insn, rtx pattern)
     }
 }
 
-
-/* Create a mov insn DEST_REG <- SRC_REG and insert it before
-   NEXT_INSN.  */
-
-static rtx_insn *
-insert_move_insn_before (rtx_insn *next_insn, rtx dest_reg, rtx src_reg)
-{
-  rtx_insn *insns;
-
-  start_sequence ();
-  emit_move_insn (dest_reg, src_reg);
-  insns = get_insns ();
-  end_sequence ();
-  emit_insn_before (insns, next_insn);
-  return insns;
-}
-
-
 /* Change mem_insn.mem_loc so that uses NEW_ADDR which has an
    increment of INC_REG.  To have reached this point, the change is a
    legitimate one from a dataflow point of view.  The only questions
@@ -490,8 +472,21 @@ attempt_change (rtx new_addr, rtx inc_reg)
 
   old_cost = (set_src_cost (mem, mode, speed)
              + set_rtx_cost (PATTERN (inc_insn.insn), speed));
+
   new_cost = set_src_cost (mem_tmp, mode, speed);
 
+  /* In the FORM_PRE_ADD and FORM_POST_ADD cases we emit an extra move
+     whose cost we should account for.  */
+  if (inc_insn.form == FORM_PRE_ADD
+      || inc_insn.form == FORM_POST_ADD)
+    {
+      start_sequence ();
+      emit_move_insn (inc_insn.reg_res, inc_insn.reg0);
+      mov_insn = get_insns ();
+      end_sequence ();
+      new_cost += seq_cost (mov_insn, speed);
+    }
+
   /* The first item of business is to see if this is profitable.  */
   if (old_cost < new_cost)
     {
@@ -522,8 +517,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
       /* Replace the addition with a move.  Do it at the location of
         the addition since the operand of the addition may change
         before the memory reference.  */
-      mov_insn = insert_move_insn_before (inc_insn.insn,
-                                         inc_insn.reg_res, inc_insn.reg0);
+      gcc_assert (mov_insn);
+      emit_insn_before (mov_insn, inc_insn.insn);
       move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
       regno = REGNO (inc_insn.reg_res);
@@ -548,8 +543,8 @@ attempt_change (rtx new_addr, rtx inc_reg)
       break;
 
     case FORM_POST_ADD:
-      mov_insn = insert_move_insn_before (mem_insn.insn,
-                                         inc_insn.reg_res, inc_insn.reg0);
+      gcc_assert (mov_insn);
+      emit_insn_before (mov_insn, mem_insn.insn);
       move_dead_notes (mov_insn, inc_insn.insn, inc_insn.reg0);
 
       /* Do not move anything to the mov insn because the instruction