public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Check rrotate optab first when transforming lrotate
@ 2019-07-15  8:59 Kewen.Lin
  2019-07-15  9:16 ` Jakub Jelinek
  0 siblings, 1 reply; 42+ messages in thread
From: Kewen.Lin @ 2019-07-15  8:59 UTC (permalink / raw)
  To: GCC Patches; +Cc: Richard Biener, Jakub Jelinek, richard.sandiford

Hi all,

In match.pd and expmed.c, we have some codes to transform lrotate to 
rrotate if rotation count is const.  But they don't consider the target
whether supports the rrotate.  It leads to some suboptimal generated
code since some optimization can't get expected result by querying
target optab.  One typical case is that we miss some rotation 
vectorization opportunity on Power.

This patch is to teach them to check target optab availability first.

Regression testing just launched, is it OK for trunk if it passed and
bootstrapped?

Thanks,
Kewen

-----------------------------------------------

gcc/ChangeLog

2019-07-15  Kewen Lin  <linkw@gcc.gnu.org>

	* expmed.c (expand_shift_1): Only transform to opposite rotate
	when it's supported on the target.
	* match.pd (lrot N -> rrot N'): Check target support or not.

gcc/testsuite/ChangeLog

2019-07-15  Kewen Lin  <linkw@gcc.gnu.org>

	* gcc.target/powerpc/vec_rotate.c: New test.


diff --git a/gcc/expmed.c b/gcc/expmed.c
index d7f8e9a5d76..6cd3341a0e4 100644
--- a/gcc/expmed.c
+++ b/gcc/expmed.c
@@ -2491,7 +2491,9 @@ expand_shift_1 (enum tree_code code, machine_mode mode, rtx shifted,
   if (rotate
       && CONST_INT_P (op1)
       && IN_RANGE (INTVAL (op1), GET_MODE_BITSIZE (scalar_mode) / 2 + left,
-                  GET_MODE_BITSIZE (scalar_mode) - 1))
+                  GET_MODE_BITSIZE (scalar_mode) - 1)
+      && ((left && optab_handler (rrotate_optab, mode) != CODE_FOR_nothing) ||
+          (!left && optab_handler (lrotate_optab, mode) != CODE_FOR_nothing)))
     {
       op1 = gen_int_shift_amount (mode, (GET_MODE_BITSIZE (scalar_mode)
                                         - INTVAL (op1)));
diff --git a/gcc/match.pd b/gcc/match.pd
index 88dae4231d8..a63cd15e129 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2418,11 +2418,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)

 /* Rewrite an LROTATE_EXPR by a constant into an
    RROTATE_EXPR by a new constant.  */
+
 (simplify
  (lrotate @0 INTEGER_CST@1)
+ (if ((VECTOR_TYPE_P (type) && target_supports_op_p (type, RROTATE_EXPR, optab_vector))
+  || (!VECTOR_TYPE_P (type) && target_supports_op_p (type, RROTATE_EXPR, optab_scalar)))
  (rrotate @0 { const_binop (MINUS_EXPR, TREE_TYPE (@1),
                            build_int_cst (TREE_TYPE (@1),
-                                          element_precision (type)), @1); }))
+                                          element_precision (type)), @1); })))

 /* Turn (a OP c1) OP c2 into a OP (c1+c2).  */
 (for op (lrotate rrotate rshift lshift)
diff --git a/gcc/testsuite/gcc.target/powerpc/vec_rotate.c b/gcc/testsuite/gcc.target/powerpc/vec_rotate.c
new file mode 100644
index 00000000000..16d1f297d2d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/powerpc/vec_rotate.c
@@ -0,0 +1,47 @@
+/* { dg-options "-O3" } */
+/* { dg-require-effective-target powerpc_vsx_ok } */
+
+/* Check LROTATE to RROTATE transformation on const rotation count is disabled
+   on Power by checking optab, it helps vectorizer to exploit vector rotation
+   instructions.  */
+
+#define N 256
+unsigned long long sud[N], rud[N];
+unsigned int suw[N], ruw[N];
+unsigned short suh[N], ruh[N];
+unsigned char sub[N], rub[N];
+
+void
+testULL ()
+{
+  for (int i = 0; i < 256; ++i)
+    rud[i] = (sud[i] >> 8) | (sud[i] << (sizeof (sud[0]) * 8 - 8));
+}
+
+void
+testUW ()
+{
+  for (int i = 0; i < 256; ++i)
+    ruw[i] = (suw[i] >> 8) | (suw[i] << (sizeof (suw[0]) * 8 - 8));
+}
+
+void
+testUH ()
+{
+  for (int i = 0; i < 256; ++i)
+    ruh[i] = (unsigned short) (suh[i] >> 9)
+            | (unsigned short) (suh[i] << (sizeof (suh[0]) * 8 - 9));
+}
+
+void
+testUB ()
+{
+  for (int i = 0; i < 256; ++i)
+    rub[i] = (unsigned char) (sub[i] >> 5)
+            | (unsigned char) (sub[i] << (sizeof (sub[0]) * 8 - 5));
+}
+
+/* { dg-final { scan-assembler {\mvrld\M} } } */
+/* { dg-final { scan-assembler {\mvrlw\M} } } */
+/* { dg-final { scan-assembler {\mvrlh\M} } } */
+/* { dg-final { scan-assembler {\mvrlb\M} } } */

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2019-08-06 15:04 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-15  8:59 Check rrotate optab first when transforming lrotate Kewen.Lin
2019-07-15  9:16 ` Jakub Jelinek
2019-07-15  9:19   ` Richard Biener
2019-07-15  9:20   ` Richard Sandiford
2019-07-15 10:54   ` Kewen.Lin
2019-07-15 14:51   ` Segher Boessenkool
     [not found]   ` <d2ccc831-c805-c7b8-5a90-cb3e5ee5ed8b@linux.ibm.com>
2019-07-16  8:48     ` [RFC] Consider lrotate const rotation in vectorizer Kewen.Lin
2019-07-17  8:42       ` [PATCH, rs6000] Support vrotr<mode>3 for int vector types Kewen.Lin
2019-07-17  8:44         ` Jakub Jelinek
2019-07-17  9:38           ` Kewen.Lin
2019-07-17 10:18             ` Jakub Jelinek
2019-07-17 13:48         ` Segher Boessenkool
2019-07-18  6:06           ` Kewen.Lin
2019-07-18 20:06             ` Segher Boessenkool
2019-07-19  6:51               ` Kewen.Lin
2019-07-19 15:49                 ` Segher Boessenkool
2019-07-23  7:32                   ` [PATCH V2, " Kewen.Lin
2019-07-25 14:24                     ` Segher Boessenkool
2019-07-26  3:33                       ` [PATCH V3, " Kewen.Lin
2019-07-26  3:37                         ` [PATCH V4, " Kewen.Lin
2019-07-26 14:28                         ` [PATCH V3, " Segher Boessenkool
2019-08-02  8:59                           ` [PATCH V5, " Kewen.Lin
2019-08-03 20:52                             ` Segher Boessenkool
2019-08-05  3:41                               ` Kewen.Lin
2019-08-05 21:50                                 ` Segher Boessenkool
2019-08-06  3:11                                   ` Kewen.Lin
2019-08-06 15:12                                     ` Segher Boessenkool
2019-07-17 10:39       ` [RFC] Consider lrotate const rotation in vectorizer Richard Biener
2019-07-17 11:19         ` Jakub Jelinek
2019-07-17 11:35           ` Richard Biener
2019-07-17 11:56             ` Richard Biener
2019-07-17 13:58             ` Segher Boessenkool
2019-07-17 17:51           ` Segher Boessenkool
2019-07-18  7:03             ` Jakub Jelinek
2019-07-18 19:45               ` Segher Boessenkool
2019-07-18 15:17             ` Richard Earnshaw (lists)
2019-07-18 15:26               ` Jakub Jelinek
2019-07-18 15:31                 ` Richard Earnshaw (lists)
2019-07-18 15:35                   ` Jakub Jelinek
2019-07-18 15:44                     ` Richard Earnshaw (lists)
2019-07-18 18:04               ` Segher Boessenkool
2019-07-18  6:28         ` Kewen.Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).