]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
h8300-protos.h: Add a prototype for same_cmp_preceding_p.
authorKazu Hirata <kazu@cs.umass.edu>
Sat, 21 Jun 2003 11:32:54 +0000 (11:32 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Sat, 21 Jun 2003 11:32:54 +0000 (11:32 +0000)
* config/h8300/h8300-protos.h: Add a prototype for
same_cmp_preceding_p.
* config/h8300/h8300.c (same_cmp_preceding): New.
* config/h8300/h8300.md: Extend peephole2's that transform
compare:SI into shorter sequences so that they can deal with
signed comparisons.

From-SVN: r68296

gcc/ChangeLog
gcc/config/h8300/h8300-protos.h
gcc/config/h8300/h8300.c
gcc/config/h8300/h8300.md

index fb790a706826137b62ca4fcd298b8814e309cdca..640677a50b9bbae0b8690147c80e0537dd87a631 100644 (file)
@@ -1,3 +1,12 @@
+2003-06-20  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * config/h8300/h8300-protos.h: Add a prototype for
+       same_cmp_preceding_p.
+       * config/h8300/h8300.c (same_cmp_preceding): New.
+       * config/h8300/h8300.md: Extend peephole2's that transform
+       compare:SI into shorter sequences so that they can deal with
+       signed comparisons.
+
 2003-06-14  Gerald Pfeifer  <pfeifer@dbai.tuwien.ac.at>
 
        * doc/contrib.texi (Contributors): Use Windows instead of Win32.
index b86b8ab1dc897b65fd896fba1a5f55936d4eea01..d1708698bb2f0eb7bbc09ea7d55cbb261a9193f4 100644 (file)
@@ -76,6 +76,7 @@ extern int iorxor_operator (rtx, enum machine_mode);
 extern int h8300_eightbit_constant_address_p (rtx);
 extern int h8300_tiny_constant_address_p (rtx);
 extern int byte_accesses_mergeable_p (rtx, rtx);
+extern int same_cmp_preceding_p (rtx);
 
 /* Used in builtins.c */
 extern rtx h8300_return_addr_rtx (int, rtx);
index 826cd6ca9bb92e2100a61260925e6f232a89e0f3..d7a55f17cf27305190c6b60ad47ff5d31651a3d9 100644 (file)
@@ -4335,6 +4335,26 @@ byte_accesses_mergeable_p (rtx addr1, rtx addr2)
 
   return 0;
 }
+
+/* Return nonzero if we have the same comparison insn as I3 two insns
+   before I3.  I3 is assumed to be a comparision insn.  */
+
+int
+same_cmp_preceding_p (rtx i3)
+{
+  rtx i1, i2;
+
+  /* Make sure we have a sequence of three insns.  */
+  i2 = prev_nonnote_insn (i3);
+  if (i2 == NULL_RTX)
+    return 0;
+  i1 = prev_nonnote_insn (i2);
+  if (i1 == NULL_RTX)
+    return 0;
+
+  return (INSN_P (i1) && rtx_equal_p (PATTERN (i1), PATTERN (i3))
+         && any_condjump_p (i2) && onlyjump_p (i2));
+}
 \f
 /* Initialize the GCC target structure.  */
 #undef TARGET_ATTRIBUTE_TABLE
index 6ec03c386d98a22cd526aef370ceab9485664d74..cae57370bf0c16b7123e60e4657b36c9ecb7d607 100644 (file)
 ;; dead     1                       eq/ne   dec.l
 ;; dead     2                       eq/ne   dec.l
 ;;
-;; dead     1                       geu/ltu shlr.l
-;; dead     3 (H8S)                 geu/ltu shlr.l
+;; dead     1                       geu/ltu shar.l
+;; dead     3 (H8S)                 geu/ltu shar.l
 ;;
 ;; ----   255                       geu/ltu mov.b
 
 ;;
 ;; into
 ;;
-;;     shlr.w  r0
+;;     shar.w  r0
 ;;     bne     .L1
 
 (define_peephole2
        (compare (match_operand:HI 0 "register_operand" "")
                 (match_operand:HI 1 "const_int_operand" "")))
    (set (pc)
-       (if_then_else (match_operator 2 "gtuleu_operator"
+       (if_then_else (match_operator 2 "gtle_operator"
                        [(cc0) (const_int 0)])
                      (label_ref (match_operand 3 "" ""))
                      (pc)))]
    && (INTVAL (operands[1]) == 1
        || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
   [(parallel [(set (match_dup 0)
-                  (lshiftrt:HI (match_dup 0)
+                  (ashiftrt:HI (match_dup 0)
                                (match_dup 5)))
              (clobber (scratch:QI))])
    (set (cc0)
        (if_then_else (match_dup 4)
                      (label_ref (match_dup 3))
                      (pc)))]
-  "operands[4] = ((GET_CODE (operands[2]) == GTU) ?
-                 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
-                 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));
+  "switch (GET_CODE (operands[2]))
+     {
+     case GTU:
+       operands[4] = gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     case LEU:
+       operands[4] = gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     default:
+       operands[4] = operands[2];
+       break;
+     }
    operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
 
 ;; Transform
 ;; dead 0xffffff?? except -1 and -2 eq/ne   xor.b and not.l
 ;; dead 0xffff??ff                  eq/ne   xor.b and not.l
 ;;
-;; live     1                       geu/ltu copy and shlr.l
-;; live     3 (H8S)                 geu/ltu copy and shlr.l
+;; live     1                       geu/ltu copy and shar.l
+;; live     3 (H8S)                 geu/ltu copy and shar.l
 ;;
-;; dead     1                       geu/ltu shlr.l
-;; dead     3 (H8S)                 geu/ltu shlr.l
+;; dead     1                       geu/ltu shar.l
+;; dead     3 (H8S)                 geu/ltu shar.l
 ;;
 ;; dead     3 (H8/300H)             geu/ltu and.b and test
 ;; dead     7                       geu/ltu and.b and test
 ;; into
 ;;
 ;;     mov.l   er0,er1
-;;     shlr.l  er1
+;;     shar.l  er1
 ;;     bne     .L1
 
+;; We avoid this transformation if we see more than one copy of the
+;; same compare insn immediately before this one.
+
 (define_peephole2
   [(match_scratch:SI 4 "r")
    (set (cc0)
        (compare (match_operand:SI 0 "register_operand" "")
                 (match_operand:SI 1 "const_int_operand" "")))
    (set (pc)
-       (if_then_else (match_operator 2 "gtuleu_operator"
+       (if_then_else (match_operator 2 "gtle_operator"
                        [(cc0) (const_int 0)])
                      (label_ref (match_operand 3 "" ""))
                      (pc)))]
   "(TARGET_H8300H || TARGET_H8300S)
    && !peep2_reg_dead_p (1, operands[0])
    && (INTVAL (operands[1]) == 1
-       || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
+       || (TARGET_H8300S && INTVAL (operands[1]) == 3))
+   && !same_cmp_preceding_p (insn)"
   [(set (match_dup 4)
        (match_dup 0))
    (parallel [(set (match_dup 4)
-                  (lshiftrt:SI (match_dup 4)
+                  (ashiftrt:SI (match_dup 4)
                                (match_dup 6)))
              (clobber (scratch:QI))])
    (set (cc0)
        (if_then_else (match_dup 5)
                      (label_ref (match_dup 3))
                      (pc)))]
-  "operands[5] = ((GET_CODE (operands[2]) == GTU) ?
-                 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
-                 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));
+  "switch (GET_CODE (operands[2]))
+     {
+     case GTU:
+       operands[5] = gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     case LEU:
+       operands[5] = gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     default:
+       operands[5] = operands[2];
+       break;
+     }
    operands[6] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
 
 ;; Transform
 ;;
 ;; into
 ;;
-;;     shlr.l  er0
+;;     shar.l  er0
 ;;     bne     .L1
 
 (define_peephole2
        (compare (match_operand:SI 0 "register_operand" "")
                 (match_operand:SI 1 "const_int_operand" "")))
    (set (pc)
-       (if_then_else (match_operator 2 "gtuleu_operator"
+       (if_then_else (match_operator 2 "gtle_operator"
                        [(cc0) (const_int 0)])
                      (label_ref (match_operand 3 "" ""))
                      (pc)))]
    && (INTVAL (operands[1]) == 1
        || (TARGET_H8300S && INTVAL (operands[1]) == 3))"
   [(parallel [(set (match_dup 0)
-                  (lshiftrt:SI (match_dup 0)
+                  (ashiftrt:SI (match_dup 0)
                                (match_dup 5)))
              (clobber (scratch:QI))])
    (set (cc0)
        (if_then_else (match_dup 4)
                      (label_ref (match_dup 3))
                      (pc)))]
-  "operands[4] = ((GET_CODE (operands[2]) == GTU) ?
-                 gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx) :
-                 gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx));
+  "switch (GET_CODE (operands[2]))
+     {
+     case GTU:
+       operands[4] = gen_rtx_NE (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     case LEU:
+       operands[4] = gen_rtx_EQ (VOIDmode, cc0_rtx, const0_rtx);
+       break;
+     default:
+       operands[4] = operands[2];
+       break;
+     }
    operands[5] = GEN_INT (exact_log2 (INTVAL (operands[1]) + 1));")
 
 ;; Transform