re PR tree-optimization/85694 (Generation of vectorized AVG (Average) instruction)
authorUros Bizjak <ubizjak@gmail.com>
Tue, 3 Jul 2018 17:33:28 +0000 (19:33 +0200)
committerUros Bizjak <uros@gcc.gnu.org>
Tue, 3 Jul 2018 17:33:28 +0000 (19:33 +0200)
PR target/85694
* config/i386/sse.md (uavg<mode>3_ceil): New expander.
(<sse2_avx2>_uavg<mode>3<mask_name>): Simplify expander.

testsuite/ChangeLog:

PR target/85694
* gcc.target/i386/pr85694.c: New test.

From-SVN: r262354

gcc/ChangeLog
gcc/config/i386/sse.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr85694.c [new file with mode: 0644]

index 4c550b6f3e415d919381f653626439ad684b1b70..7f5fa7b97df243aa9faf8454b2262dcafa42525a 100644 (file)
@@ -1,3 +1,9 @@
+2018-07-03  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR target/85694
+       * config/i386/sse.md (uavg<mode>3_ceil): New expander.
+       (<sse2_avx2>_uavg<mode>3<mask_name>): Simplify expander.
+
 2018-07-03  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR tree-optimization/85694
index 0420da8035c7436af296693bca7b06354c344e8f..d2722fdfcd0c67ebc31093115e57c3fc63322180 100644 (file)
   DONE;
 })
 
+(define_expand "uavg<mode>3_ceil"
+  [(set (match_operand:VI12_AVX2 0 "register_operand")
+       (truncate:VI12_AVX2
+         (lshiftrt:<ssedoublemode>
+           (plus:<ssedoublemode>
+             (plus:<ssedoublemode>
+               (zero_extend:<ssedoublemode>
+                 (match_operand:VI12_AVX2 1 "vector_operand"))
+               (zero_extend:<ssedoublemode>
+                 (match_operand:VI12_AVX2 2 "vector_operand")))
+             (match_dup 3))
+           (const_int 1))))]
+  "TARGET_SSE2"
+{
+  operands[3] = CONST1_RTX(<MODE>mode);
+  ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
+})
+
 (define_expand "usadv16qi"
   [(match_operand:V4SI 0 "register_operand")
    (match_operand:V16QI 1 "register_operand")
            (const_int 1))))]
   "TARGET_SSE2 && <mask_mode512bit_condition> && <mask_avx512bw_condition>"
 {
-  rtx tmp;
-  if (<mask_applied>)
-    tmp = operands[3];
-  operands[3] = CONST1_RTX(<MODE>mode);
+  operands[<mask_expand_op3>] = CONST1_RTX(<MODE>mode);
   ix86_fixup_binary_operands_no_copy (PLUS, <MODE>mode, operands);
-
-  if (<mask_applied>)
-    {
-      operands[5] = operands[3];
-      operands[3] = tmp;
-    }
 })
 
 (define_insn "*<sse2_avx2>_uavg<mode>3<mask_name>"
index 2afad58666b80dce1a4122fd61eab8b3cb392b78..d18061088b8428ecb829fe9f41f584b07d29ad54 100644 (file)
@@ -3,6 +3,11 @@
        PR c++/86201
        * g++.dg/diagnostic/pr86201.C: New test.
 
+2018-07-03  Uros Bizjak  <ubizjak@gmail.com>
+
+       PR target/85694
+       * gcc.target/i386/pr85694.c: New test.
+
 2018-07-03  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR tree-optimization/85694
diff --git a/gcc/testsuite/gcc.target/i386/pr85694.c b/gcc/testsuite/gcc.target/i386/pr85694.c
new file mode 100644 (file)
index 0000000..b730d23
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile }
+/* { dg-options "-msse2 -O2 -ftree-vectorize" } */
+/* { dg-final { scan-assembler "pavgb" } } */
+/* { dg-final { scan-assembler "pavgw" } } */
+
+#define N 1024
+
+#define TEST(TYPE)                                             \
+  unsigned TYPE a_##TYPE[N], b_##TYPE[N], c_##TYPE[N];         \
+  void f_##TYPE (void)                                         \
+  {                                                            \
+    int i;                                                     \
+    for (i = 0; i < N; i++)                                    \
+      a_##TYPE[i] = (b_##TYPE[i] + c_##TYPE[i] + 1) >> 1;      \
+  }
+
+TEST(char);
+TEST(short);