]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* loop-doloop.c (doloop_modify): Pass doloop_end pattern to
authoramylaar <amylaar@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Oct 2012 16:11:00 +0000 (16:11 +0000)
committeramylaar <amylaar@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 16 Oct 2012 16:11:00 +0000 (16:11 +0000)
        gen_doloop_begin.
        (doloop_optimize): Pass flag to indicate if loop is entered at top
        to gen_doloop_end.
        * config/arm/thumb2.md (doloop_end): Accept extra operand.
        * config/bfin/bfin.md (doloop_end): Likewise.
        * config/c6x/c6x.md (doloop_end): Likewise.
        * config/ia64/ia64.md (doloop_end): Likewise.
        * config/mep/mep.md (doloop_begin, doloop_end): Likewise.
        * config/rs6000/rs6000.md (doloop_end): Likewise.
        * config/s390/s390.md (doloop_end): Likewise.
        * config/sh/sh.md (doloop_end): Likewise.
        * config/spu/spu.md (doloop_end): Likewise.
        * config/tilegx/tilegx.md (doloop_end): Likewise.
        * config/tilepro/tilepro.md (doloop_end): Likewise.
        * doc/md.texi (doloop_end): Document new operand.
        * basic-block.h (contains_no_active_insn_p): Declare.
        * cfgrtl.c (contains_no_active_insn_p): New function, factored
        out of ...
        (forwarder_block_p): ... here.

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

16 files changed:
gcc/ChangeLog
gcc/basic-block.h
gcc/cfgrtl.c
gcc/config/arm/thumb2.md
gcc/config/bfin/bfin.md
gcc/config/c6x/c6x.md
gcc/config/ia64/ia64.md
gcc/config/mep/mep.md
gcc/config/rs6000/rs6000.md
gcc/config/s390/s390.md
gcc/config/sh/sh.md
gcc/config/spu/spu.md
gcc/config/tilegx/tilegx.md
gcc/config/tilepro/tilepro.md
gcc/doc/md.texi
gcc/loop-doloop.c

index 7542474a53e2e9d67767b006641c85781790040f..0b14270ee51215e08de9b65db261039f980b9278 100644 (file)
@@ -1,3 +1,26 @@
+2012-10-16  Joern Rennecke  <joern.rennecke@embecosm.com>
+
+       * loop-doloop.c (doloop_modify): Pass doloop_end pattern to
+       gen_doloop_begin.
+       (doloop_optimize): Pass flag to indicate if loop is entered at top
+       to gen_doloop_end.
+       * config/arm/thumb2.md (doloop_end): Accept extra operand.
+       * config/bfin/bfin.md (doloop_end): Likewise.
+       * config/c6x/c6x.md (doloop_end): Likewise.
+       * config/ia64/ia64.md (doloop_end): Likewise.
+       * config/mep/mep.md (doloop_begin, doloop_end): Likewise.
+       * config/rs6000/rs6000.md (doloop_end): Likewise.
+       * config/s390/s390.md (doloop_end): Likewise.
+       * config/sh/sh.md (doloop_end): Likewise.
+       * config/spu/spu.md (doloop_end): Likewise.
+       * config/tilegx/tilegx.md (doloop_end): Likewise.
+       * config/tilepro/tilepro.md (doloop_end): Likewise.
+       * doc/md.texi (doloop_end): Document new operand.
+       * basic-block.h (contains_no_active_insn_p): Declare.
+       * cfgrtl.c (contains_no_active_insn_p): New function, factored
+       out of ...
+       (forwarder_block_p): ... here.
+
 2012-10-16  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        PR c/53063
index 61351fb248de6a393d0176a74b2f7a501c7c6270..d9bd3b7e550d7f0c5254ce030a9ded75ab7fc63e 100644 (file)
@@ -802,6 +802,7 @@ extern bool purge_all_dead_edges (void);
 extern bool purge_dead_edges (basic_block);
 extern bool fixup_abnormal_edges (void);
 extern basic_block force_nonfallthru_and_redirect (edge, basic_block, rtx);
+extern bool contains_no_active_insn_p (const_basic_block);
 extern bool forwarder_block_p (const_basic_block);
 extern bool can_fallthru (basic_block, basic_block);
 
index 1b578d7feeb31fbbe06b4d056e7b7ccdd5798619..b58562fcc5f5851a080c2ec8a7bfaab0028c12ad 100644 (file)
@@ -541,10 +541,9 @@ flow_active_insn_p (const_rtx insn)
 
 /* Return true if the block has no effect and only forwards control flow to
    its single destination.  */
-/* FIXME: Make this a cfg hook.  */
 
 bool
-forwarder_block_p (const_basic_block bb)
+contains_no_active_insn_p (const_basic_block bb)
 {
   rtx insn;
 
@@ -552,6 +551,24 @@ forwarder_block_p (const_basic_block bb)
       || !single_succ_p (bb))
     return false;
 
+  for (insn = BB_HEAD (bb); insn != BB_END (bb); insn = NEXT_INSN (insn))
+    if (INSN_P (insn) && flow_active_insn_p (insn))
+      return false;
+
+  return (!INSN_P (insn)
+         || (JUMP_P (insn) && simplejump_p (insn))
+         || !flow_active_insn_p (insn));
+}
+
+/* Likewise, but protect loop latches, headers and preheaders.  */
+/* FIXME: Make this a cfg hook.  */
+
+bool
+forwarder_block_p (const_basic_block bb)
+{
+  if (!contains_no_active_insn_p (bb))
+    return false;
+
   /* Protect loop latches, headers and preheaders.  */
   if (current_loops)
     {
@@ -563,13 +580,7 @@ forwarder_block_p (const_basic_block bb)
        return false;
     }
 
-  for (insn = BB_HEAD (bb); insn != BB_END (bb); insn = NEXT_INSN (insn))
-    if (INSN_P (insn) && flow_active_insn_p (insn))
-      return false;
-
-  return (!INSN_P (insn)
-         || (JUMP_P (insn) && simplejump_p (insn))
-         || !flow_active_insn_p (insn));
+  return true;
 }
 
 /* Return nonzero if we can reach target from src by falling through.  */
index 57d1539ee3d9d882bb135f2519d085167fb8865d..a5302f479f5091d08f4bf1a9ee9b0423692372af 100644 (file)
    (use (match_operand 1 "" ""))      ; iterations; zero if unknown
    (use (match_operand 2 "" ""))      ; max iterations
    (use (match_operand 3 "" ""))      ; loop level
-   (use (match_operand 4 "" ""))]     ; label
+   (use (match_operand 4 "" ""))      ; label
+   (use (match_operand 5 "" ""))]     ; flag: 1 if loop entered at top, else 0
   "TARGET_32BIT"
   "
  {
index 1774d3adff668c124239b849b394c669bf3cf028..63ad1755020e35b54d94c57ed206ac1f0733ac4e 100644 (file)
 ; operand 2 is the maximum number of loop iterations
 ; operand 3 is the number of levels of enclosed loops
 ; operand 4 is the label to jump to at the top of the loop
+; operand 5 indicates if the loop is entered at the top
 (define_expand "doloop_end"
   [(parallel [(set (pc) (if_then_else
                          (ne (match_operand:SI 0 "" "")
                   (plus:SI (match_dup 0)
                            (const_int -1)))
              (unspec [(const_int 0)] UNSPEC_LSETUP_END)
-             (clobber (match_scratch:SI 5 ""))])]
+             (clobber (match_operand 5 ""))])] ; match_scratch
   ""
 {
   /* The loop optimizer doesn't check the predicates... */
       && (unsigned HOST_WIDE_INT) INTVAL (operands[2]) >= 0xFFFFFFFF)
     FAIL;
   bfin_hardware_loop ();
+  operands[5] = gen_rtx_SCRATCH (SImode);
 })
 
 (define_insn "loop_end"
index 99f02d5dc98658d561fab05ec89000966c96044d..e612ef6829382432d547fb0c632ed8f70cd88692 100644 (file)
 ; operand 2 is the maximum number of loop iterations
 ; operand 3 is the number of levels of enclosed loops
 ; operand 4 is the label to jump to at the top of the loop
+; operand 5 indicates if the loop is entered at the top
 (define_expand "doloop_end"
   [(parallel [(set (pc) (if_then_else
                          (ne (match_operand:SI 0 "" "")
              (set (match_dup 0)
                   (plus:SI (match_dup 0)
                            (const_int -1)))
-             (clobber (match_scratch:SI 5 ""))])]
+             (clobber (match_operand 5 ""))])] ; match_scratch
   "TARGET_INSNS_64PLUS && optimize"
 {
   /* The loop optimizer doesn't check the predicates... */
   if (GET_MODE (operands[0]) != SImode)
     FAIL;
+  operands[5] = gen_rtx_SCRATCH (SImode);
 })
 
 (define_insn "mvilc"
index aa5e78636ea38f9c162d1cc1439841ccee2ce720..f84f1ad633257005ada2d3ef7dd377e6ff4d2b67 100644 (file)
    (use (match_operand 1 "" ""))       ; iterations; zero if unknown
    (use (match_operand 2 "" ""))       ; max iterations
    (use (match_operand 3 "" ""))       ; loop level
-   (use (match_operand 4 "" ""))]      ; label
+   (use (match_operand 4 "" ""))       ; label
+   (use (match_operand 5 "" ""))]      ; flag: 1 if loop entered at top, else 0
   ""
 {
   /* Only use cloop on innermost loops.  */
index 773a9a0aa1418cf1791e95c0d2e87f653b7965bc..35b6e1490bc3dd66b07abcd6bcda19a7a76ade13 100644 (file)
   [(use (match_operand 0 "register_operand" ""))
    (use (match_operand:QI 1 "const_int_operand" ""))
    (use (match_operand:QI 2 "const_int_operand" ""))
-   (use (match_operand:QI 3 "const_int_operand" ""))]
+   (use (match_operand:QI 3 "const_int_operand" ""))
+   (use (match_operand 4 "" ""))]
   "!profile_arc_flag && TARGET_OPT_REPEAT"
   "if (INTVAL (operands[3]) > 1)
      FAIL;
    (use (match_operand:QI 1 "const_int_operand" ""))
    (use (match_operand:QI 2 "const_int_operand" ""))
    (use (match_operand:QI 3 "const_int_operand" ""))
-   (use (label_ref (match_operand 4 "" "")))]
+   (use (label_ref (match_operand 4 "" "")))
+   (use (match_operand 5 "" ""))]
   "!profile_arc_flag && TARGET_OPT_REPEAT"
   "if (INTVAL (operands[3]) > 1)
      FAIL;
index 96f4f6a83211d00c31db99148118f85299d9f1c9..5bf2fec18e4f996853a9228c9839554a08ca16b3 100644 (file)
    (use (match_operand 1 "" ""))       ; iterations; zero if unknown
    (use (match_operand 2 "" ""))       ; max iterations
    (use (match_operand 3 "" ""))       ; loop level
-   (use (match_operand 4 "" ""))]      ; label
+   (use (match_operand 4 "" ""))       ; label
+   (use (match_operand 5 "" ""))]      ; flag: 1 if loop entered at top, else 0
   ""
   "
 {
index efe1a470e8d3abdd077a3464d9f4ca2e18fcd586..9279a9876c4fc07c7a536df3ec415656624c852f 100644 (file)
    (use (match_operand 1 "" ""))        ; iterations; zero if unknown
    (use (match_operand 2 "" ""))        ; max iterations
    (use (match_operand 3 "" ""))        ; loop level
-   (use (match_operand 4 "" ""))]       ; label
+   (use (match_operand 4 "" ""))        ; label
+   (use (match_operand 5 "" ""))]       ; flag: 1 if loop entered at top, else 0
   ""
 {
   if (GET_MODE (operands[0]) == SImode && !TARGET_CPU_ZARCH)
index 6e6394504f69a438d74f6f95bc9c91d2a8c72b1f..2ef4a1a4ee0b6158c549c53637e50293af4ea686 100644 (file)
@@ -8474,11 +8474,14 @@ label:
                          (pc)))
              (set (match_dup 0)
                   (plus:SI (match_dup 0) (const_int -1)))
-             (clobber (reg:SI T_REG))])]
+             (clobber (reg:SI T_REG))])
+   (match_operand 5 "" "")]
   "TARGET_SH2"
 {
   if (GET_MODE (operands[0]) != SImode)
     FAIL;
+  emit_insn (gen_doloop_end_split (operands[0], operands[4], operands[0]));
+  DONE;
 })
 
 (define_insn_and_split "doloop_end_split"
index ee5fced6665c39589c089727ddddfc24b1640750..3446e986f2712ff5f7e95ba21db29750ef6da7fe 100644 (file)
@@ -4490,7 +4490,8 @@ selb\t%0,%4,%0,%3"
     (use (match_operand 1 "" ""))      ; iterations; zero if unknown
     (use (match_operand 2 "" ""))      ; max iterations
     (use (match_operand 3 "" ""))      ; loop level
-    (use (match_operand 4 "" ""))]     ; label
+    (use (match_operand 4 "" ""))      ; label
+    (match_operand 5 "" "")]
    ""
    "
  {
index 92a6d651edab8861887c7da61dd380d5dda652cb..b5dc9c8844fd99c0fcd042d97ca8485ce1a4615d 100644 (file)
    (use (match_operand 1 "" ""))    ;; iterations; zero if unknown
    (use (match_operand 2 "" ""))    ;; max iterations
    (use (match_operand 3 "" ""))    ;; loop level
-   (use (match_operand 4 "" ""))]   ;; label
+   (use (match_operand 4 "" ""))    ;; label
+   (use (match_operand 5 "" ""))]   ;; flag: 1 if loop entered at top, else 0
    ""
 {
   if (optimize > 0 && flag_modulo_sched)
index 9d5d44e85ed392292aa6bf81bd3b227a07b60904..1d1838e6de877f22a1d3db14d238f7c45c089a6e 100644 (file)
    (use (match_operand 1 "" ""))    ;; iterations; zero if unknown
    (use (match_operand 2 "" ""))    ;; max iterations
    (use (match_operand 3 "" ""))    ;; loop level
-   (use (match_operand 4 "" ""))]   ;; label
+   (use (match_operand 4 "" ""))    ;; label
+   (use (match_operand 5 "" ""))]   ;; flag: 1 if loop entered at top, else 0
    ""
 {
   if (optimize > 0)
index 6a1db6ad607d2fb22374aa9264294a20e65f2b9f..32866d5c156d03b975e0bbf3657ecd0b0beaa0df 100644 (file)
@@ -5517,7 +5517,9 @@ iterations as a @code{const_int} or @code{const0_rtx} if this cannot be
 determined until run-time; operand 2 is the actual or estimated maximum
 number of iterations as a @code{const_int}; operand 3 is the number of
 enclosed loops as a @code{const_int} (an innermost loop has a value of
-1); operand 4 is the label to jump to if the register is nonzero.
+1); operand 4 is the label to jump to if the register is nonzero;
+operand 5 is const1_rtx if the loop in entered at its top, const0_rtx
+otherwise.
 @xref{Looping Patterns}.
 
 This optional instruction pattern should be defined for machines with
index 8dcfea5bba83122f72783797c0efedd36517d2a1..9be87c64aea0a0598d969202b0d885267dcb08e4 100644 (file)
@@ -1,5 +1,5 @@
 /* Perform doloop optimizations
-   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010
+   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2012
    Free Software Foundation, Inc.
    Based on code by Michael P. Hayes (m.hayes@elec.canterbury.ac.nz)
 
@@ -561,7 +561,8 @@ doloop_modify (struct loop *loop, struct niter_desc *desc,
     init = gen_doloop_begin (counter_reg,
                             desc->const_iter ? desc->niter_expr : const0_rtx,
                             iter_rtx,
-                            GEN_INT (level));
+                            GEN_INT (level),
+                            doloop_seq);
     if (init)
       {
        start_sequence ();
@@ -619,6 +620,7 @@ doloop_optimize (struct loop *loop)
   unsigned word_mode_size;
   unsigned HOST_WIDE_INT word_mode_max;
   double_int iter;
+  int entered_at_top;
 
   if (dump_file)
     fprintf (dump_file, "Doloop: Processing loop %d.\n", loop->num);
@@ -681,8 +683,14 @@ doloop_optimize (struct loop *loop)
      not like.  */
   start_label = block_label (desc->in_edge->dest);
   doloop_reg = gen_reg_rtx (mode);
+  entered_at_top = loop_preheader_edge (loop)->dest == desc->in_edge->dest;
+  fprintf (stderr, "entered at top orig: %d\n", entered_at_top);
+  entered_at_top = (loop->latch == desc->in_edge->dest
+                      && contains_no_active_insn_p (loop->latch));
+  fprintf (stderr, "entered at top Zdenek: %d\n", entered_at_top);
   doloop_seq = gen_doloop_end (doloop_reg, iterations, iterations_max,
-                              GEN_INT (level), start_label);
+                              GEN_INT (level), start_label,
+                              GEN_INT (entered_at_top));
 
   word_mode_size = GET_MODE_PRECISION (word_mode);
   word_mode_max
@@ -712,7 +720,8 @@ doloop_optimize (struct loop *loop)
        }
       PUT_MODE (doloop_reg, word_mode);
       doloop_seq = gen_doloop_end (doloop_reg, iterations, iterations_max,
-                                  GEN_INT (level), start_label);
+                                  GEN_INT (level), start_label,
+                                  GEN_INT (entered_at_top));
     }
   if (! doloop_seq)
     {