S/390: Define shift_truncation_mask.
authorRobin Dapp <rdapp@linux.ibm.com>
Mon, 8 Jul 2019 14:42:49 +0000 (14:42 +0000)
committerRobin Dapp <rdapp@gcc.gnu.org>
Mon, 8 Jul 2019 14:42:49 +0000 (14:42 +0000)
Define s390_shift_truncation_mask to allow the optabs optimization

    sh = (64 - sh)
 -> sh = -sh

for a rotation operation.

gcc/ChangeLog:

2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>

* config/s390/s390.c (s390_shift_truncation_mask): Define.
(TARGET_SHIFT_TRUNCATION_MASK): Define.

gcc/testsuite/ChangeLog:

2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>

* gcc.target/s390/rotate-truncation-mask.c: New test.

From-SVN: r273237

gcc/ChangeLog
gcc/config/s390/s390.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c [new file with mode: 0644]

index c4f0503..b47aead 100644 (file)
@@ -1,5 +1,10 @@
 2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>
 
+       * config/s390/s390.c (s390_shift_truncation_mask): Define.
+       (TARGET_SHIFT_TRUNCATION_MASK): Define.
+
+2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>
+
        * config/s390/constraints.md: Add new jsc constraint.
        * config/s390/predicates.md: New predicates.
        * config/s390/s390-protos.h (s390_valid_shift_count): New function.
index 324d9d2..75b0b5b 100644 (file)
@@ -16412,7 +16412,13 @@ s390_sched_dependencies_evaluation (rtx_insn *head, rtx_insn *tail)
   add_dependence (r11_restore, r15_restore, REG_DEP_ANTI);
 }
 
+/* Implement TARGET_SHIFT_TRUNCATION_MASK for integer shifts.  */
 
+static unsigned HOST_WIDE_INT
+s390_shift_truncation_mask (machine_mode mode)
+{
+  return mode == DImode || mode == SImode ? 63 : 0;
+}
 
 /* Initialize GCC target structure.  */
 
@@ -16709,6 +16715,8 @@ s390_sched_dependencies_evaluation (rtx_insn *head, rtx_insn *tail)
 #define TARGET_SCHED_DEPENDENCIES_EVALUATION_HOOK \
   s390_sched_dependencies_evaluation
 
+#undef TARGET_SHIFT_TRUNCATION_MASK
+#define TARGET_SHIFT_TRUNCATION_MASK s390_shift_truncation_mask
 
 /* Use only short displacement, since long displacement is not available for
    the floating point instructions.  */
index b1c6ea2..a7a67fb 100644 (file)
@@ -1,5 +1,9 @@
 2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>
 
+       * gcc.target/s390/rotate-truncation-mask.c: New test.
+
+2019-07-08  Robin Dapp  <rdapp@linux.ibm.com>
+
        * gcc.target/s390/combine-rotate-modulo.c: New test.
        * gcc.target/s390/combine-shift-rotate-add-mod.c: New test.
        * gcc.target/s390/vector/combine-shift-vec.c: New test.
diff --git a/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c b/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c
new file mode 100644 (file)
index 0000000..1cdd209
--- /dev/null
@@ -0,0 +1,11 @@
+/* Check that we do not use (64 - sh) for rotating.  */
+
+/* { dg-options "-O1 -m64" } */
+
+/* { dg-final { scan-assembler "lcr\t%r.+,%r.+" } } */
+/* { dg-final { scan-assembler-not "lhi\t%r.+,64" } } */
+/* { dg-final { scan-assembler-not "sr\t%r.+,%r.+" } } */
+unsigned long rotr (unsigned long in, unsigned long sh)
+{
+   return (in >> sh) | (in << (64 - sh));
+}