diff mbox

Re-enable shadd insns on the PA

Message ID 555CF897.4060900@redhat.com
State New
Headers show

Commit Message

Jeff Law May 20, 2015, 9:11 p.m. UTC
This is the first in a series of patches to fix the fallout from recent 
combiner changes in how shift-add style insns are canonicalized.

This patch effectively just adds a new shift-add insn to the PA port. 
The old shift-add insn stays for now, but will be removed in a follow-up 
once I'm confident all the ways we might generate that insn have been 
updated on the trunk.

My sole remaining PA is dead and the one I had access to via 
parisc-linux.org doesn't seem to be responding.  So testing is limited.

The goal is to generate the same code as we had before the combiner 
changes across the 300+ .i files for a gcc-4.7.3 build on the PA.  This 
patch (in conjuction with several others) has accomplished that goal. 
I'm obviously cherry picking individual hunks out of that work, cleaning 
them up and committing them.

This patch also creates a hppa target testsuite.  Not that it'll ever be 
all that large, we might as well not pollute the rest of the suite with 
PA specific tests.

Installed on the trunk.



Jeff
commit 7176b30ff9f6b2ea07950d392cad0876123dc5e4
Author: Jeff Law <law@redhat.com>
Date:   Wed May 20 15:07:34 2015 -0600

    2015-05-20  Jeff Law  <law@redhat.com>
    
    	* config/pa/pa.c (pa_print_operand): New 'o' output modifier.
    	(pa_mem_shadd_constant_p): Renamed from pa_shadd_constant_p.
    	(pa_shadd_constant_p): Allow constants for shadd insns rather
    	than valid scaling constants for memory addresses.
    	* config/pa/pa-protos.h (pa_mem_shadd_constant_p): Add prototype.
    	* config/pa/predicates.md (mem_shadd_operand): New predicate.
    	* config/pa/pa.md (shift-add insns using MULT): Use mem_shadd_operand.
    	(shift-add insns using ASHIFT): New patterns.
    
    	* gcc.target/hppa/hppa.exp: New target test driver.
    	* gcc.target/hppa/shadd-1.c: New test.
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5bcbcb4..490386e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@ 
+2015-05-20  Jeff Law  <law@redhat.com>
+
+	* config/pa/pa.c (pa_print_operand): New 'o' output modifier.
+	(pa_mem_shadd_constant_p): Renamed from pa_shadd_constant_p.
+	(pa_shadd_constant_p): Allow constants for shadd insns rather
+	than valid scaling constants for memory addresses.
+	* config/pa/pa-protos.h (pa_mem_shadd_constant_p): Add prototype.
+	* config/pa/predicates.md (mem_shadd_operand): New predicate.
+	* config/pa/pa.md (shift-add insns using MULT): Use mem_shadd_operand.
+	(shift-add insns using ASHIFT): New patterns.
+
 2015-05-20  Mikhail Maltsev  <maltsevm@gmail.com>
 
 	* bb-reorder.c (set_edge_can_fallthru_flag): Use rtx_jump_insn where
diff --git a/gcc/config/pa/pa-protos.h b/gcc/config/pa/pa-protos.h
index 4a44dab..58cc463 100644
--- a/gcc/config/pa/pa-protos.h
+++ b/gcc/config/pa/pa-protos.h
@@ -85,6 +85,7 @@  extern int pa_and_mask_p (unsigned HOST_WIDE_INT);
 extern int pa_cint_ok_for_move (HOST_WIDE_INT);
 extern int pa_ior_mask_p (unsigned HOST_WIDE_INT);
 extern int pa_ldil_cint_p (HOST_WIDE_INT);
+extern int pa_mem_shadd_constant_p (int);
 extern int pa_shadd_constant_p (int);
 extern int pa_zdepi_cint_p (unsigned HOST_WIDE_INT);
 
diff --git a/gcc/config/pa/pa.c b/gcc/config/pa/pa.c
index cfdafa6..f99cf33 100644
--- a/gcc/config/pa/pa.c
+++ b/gcc/config/pa/pa.c
@@ -5242,6 +5242,11 @@  pa_print_operand (FILE *file, rtx x, int code)
       gcc_assert (GET_CODE (x) == CONST_INT);
       fprintf (file, HOST_WIDE_INT_PRINT_DEC, 32 - (INTVAL (x) & 31));
       return;
+    case 'o':
+      gcc_assert (GET_CODE (x) == CONST_INT
+		  && (INTVAL (x) == 1 || INTVAL (x) == 2 || INTVAL (x) == 3));
+      fprintf (file, "%d", INTVAL (x));
+      return;
     case 'O':
       gcc_assert (GET_CODE (x) == CONST_INT && exact_log2 (INTVAL (x)) >= 0);
       fprintf (file, "%d", exact_log2 (INTVAL (x)));
@@ -8729,11 +8734,22 @@  pa_fmpysuboperands (rtx *operands)
 }
 
 /* Return 1 if the given constant is 2, 4, or 8.  These are the valid
+   constants for a MULT embedded inside a memory address.  */
+int
+pa_mem_shadd_constant_p (int val)
+{
+  if (val == 2 || val == 4 || val == 8)
+    return 1;
+  else
+    return 0;
+}
+
+/* Return 1 if the given constant is 1, 2, or 3.  These are the valid
    constants for shadd instructions.  */
 int
 pa_shadd_constant_p (int val)
 {
-  if (val == 2 || val == 4 || val == 8)
+  if (val == 1 || val == 2 || val == 3)
     return 1;
   else
     return 0;
diff --git a/gcc/config/pa/pa.md b/gcc/config/pa/pa.md
index cc077a4..73c8f6b 100644
--- a/gcc/config/pa/pa.md
+++ b/gcc/config/pa/pa.md
@@ -6337,7 +6337,7 @@ 
 (define_insn ""
   [(set (match_operand:SI 0 "register_operand" "=r")
 	(plus:SI (mult:SI (match_operand:SI 2 "register_operand" "r")
-			  (match_operand:SI 3 "shadd_operand" ""))
+			  (match_operand:SI 3 "mem_shadd_operand" ""))
 		 (match_operand:SI 1 "register_operand" "r")))]
   ""
   "{sh%O3addl %2,%1,%0|shladd,l %2,%O3,%1,%0} "
@@ -6347,13 +6347,33 @@ 
 (define_insn ""
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(plus:DI (mult:DI (match_operand:DI 2 "register_operand" "r")
-			  (match_operand:DI 3 "shadd_operand" ""))
+			  (match_operand:DI 3 "mem_shadd_operand" ""))
 		 (match_operand:DI 1 "register_operand" "r")))]
   "TARGET_64BIT"
   "shladd,l %2,%O3,%1,%0"
   [(set_attr "type" "binary")
    (set_attr "length" "4")])
 
+(define_insn ""
+  [(set (match_operand:SI 0 "register_operand" "=r")
+	(plus:SI (ashift:SI (match_operand:SI 2 "register_operand" "r")
+			    (match_operand:SI 3 "shadd_operand" ""))
+		 (match_operand:SI 1 "register_operand" "r")))]
+  ""
+  "{sh%o3addl %2,%1,%0|shladd,l %2,%o3,%1,%0} "
+  [(set_attr "type" "binary")
+   (set_attr "length" "4")])
+
+(define_insn ""
+  [(set (match_operand:DI 0 "register_operand" "=r")
+	(plus:DI (ashift:DI (match_operand:DI 2 "register_operand" "r")
+			    (match_operand:DI 3 "shadd_operand" ""))
+		 (match_operand:DI 1 "register_operand" "r")))]
+  "TARGET_64BIT"
+  "shladd,l %2,%o3,%1,%0"
+  [(set_attr "type" "binary")
+   (set_attr "length" "4")])
+
 (define_expand "ashlsi3"
   [(set (match_operand:SI 0 "register_operand" "")
 	(ashift:SI (match_operand:SI 1 "lhs_lshift_operand" "")
diff --git a/gcc/config/pa/predicates.md b/gcc/config/pa/predicates.md
index fcf6846..bbbaa85 100644
--- a/gcc/config/pa/predicates.md
+++ b/gcc/config/pa/predicates.md
@@ -581,6 +581,10 @@ 
 ;; Return 1 if OP is a CONST_INT with the value 2, 4, or 8.  These are
 ;; the valid constants for shadd instructions.
 
+(define_predicate "mem_shadd_operand"
+  (and (match_code "const_int")
+       (match_test "pa_mem_shadd_constant_p (INTVAL (op))")))
+
 (define_predicate "shadd_operand"
   (and (match_code "const_int")
        (match_test "pa_shadd_constant_p (INTVAL (op))")))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index ed2fc32..f20a131 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2015-05-20  Jeff Law  <law@redhat.com>
+
+	* gcc.target/hppa/hppa.exp: New target test driver.
+	* gcc.target/hppa/shadd-1.c: New test.
+
 2015-05-20  Alex Velenko  <Alex.Velenko@arm.com>
 
         * gcc.target/arm/thumb1-far-jump-2.c (r4): Added int in definition.
diff --git a/gcc/testsuite/gcc.target/hppa/hppa.exp b/gcc/testsuite/gcc.target/hppa/hppa.exp
new file mode 100644
index 0000000..a47141d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/hppa/hppa.exp
@@ -0,0 +1,41 @@ 
+# Copyright (C) 1997-2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an m68k target.
+if { ![istarget hppa*-*-*] } then {
+  return
+}
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cCS\]]] \
+	"" $DEFAULT_CFLAGS
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gcc.target/hppa/shadd-1.c b/gcc/testsuite/gcc.target/hppa/shadd-1.c
new file mode 100644
index 0000000..de4776b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/hppa/shadd-1.c
@@ -0,0 +1,16 @@ 
+/* { dg-do compile }  */
+/* { dg-options "-O2" }  */
+/* { dg-final { scan-assembler-times "sh.add" 1 } }  */
+
+typedef struct
+{
+  unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))];
+}
+__sigset_t;
+int
+__sigaddset (__sigset_t * __set, int __sig, int __stuff)
+{
+  unsigned long int __word =
+    (((__sig) - 1) / (8 * sizeof (unsigned long int)));
+  return __set->__val[__word] |= __stuff;
+}