Define s390_shift_truncation_mask to allow the optabs optimization

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

for a rotation operation.

--

gcc/ChangeLog:

2019-07-05  Robin Dapp  <rd...@linux.ibm.com>

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

gcc/testsuite/ChangeLog:

2019-07-05  Robin Dapp  <rd...@linux.ibm.com>

        * gcc.target/s390/rotate-truncation-mask.c: New test.
---
 gcc/config/s390/s390.c                                |  8 ++++++++
 .../gcc.target/s390/rotate-truncation-mask.c          | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 324d9d23210..75b0b5b4790 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -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.  */
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
index 00000000000..1cdd20913b9
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/rotate-truncation-mask.c
@@ -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));
+}
-- 
2.17.0

Reply via email to