Constant fold even masked shift builtins

Message ID 20180511081059.GN8577@tucnak
State New
Headers show
Series
  • Constant fold even masked shift builtins
Related show

Commit Message

Jakub Jelinek May 11, 2018, 8:10 a.m.
Hi!

On top of the earlier 3 pending patches, this patch adds constant folding
of the shifts even when the mask is not all ones (as long as the orig value
argument is VECTOR_CST too).  Then we can just do the blend according to the
constant mask.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Just short note how some of these testcase expected results were created,
I'm adding
int
main ()
{
  foo ();
  bar ();
  baz ();
  int i, j;
  {
  __m128i *p = (__m128i *) &s1;
  for (i = 0; i < 18; i++, p++)
    {
      __builtin_printf ("/* { dg-final { scan-tree-dump-times \"s1.%c = \\{ ", 'a' + i);
      for (j = 0; j < 2; j++)
        __builtin_printf ("%lld%s", (*p)[j], j == 1 ? " \\};\" 1 \"optimized\" } } */\n" : ", ");
    }
  }
  {
  __m256i *p = (__m256i *) &s2;
  for (i = 0; i < 18; i++, p++)
    {
      __builtin_printf ("/* { dg-final { scan-tree-dump-times \"s2.%c = \\{ ", 'a' + i);
      for (j = 0; j < 4; j++)
        __builtin_printf ("%lld%s", (*p)[j], j == 3 ? " \\};\" 1 \"optimized\" } } */\n" : ", ");
    }
  }
  {
  __m512i *p = (__m512i *) &s3;
  for (i = 0; i < 18; i++, p++)
    {
      __builtin_printf ("/* { dg-final { scan-tree-dump-times \"s3.%c = \\{ ", 'a' + i);
      for (j = 0; j < 8; j++)
        __builtin_printf ("%lld%s", (*p)[j], j == 7 ? " \\};\" 1 \"optimized\" } } */\n" : ", ");
    }
  }
  return 0;
}
code at the end without the i386.c changes (so no folding is done), run the
resulting program under simulator and adding the directives it printed into
the testcase.

2018-05-11  Jakub Jelinek  <jakub@redhat.com>

	PR target/85323
	* config/i386/i386.c (ix86_fold_builtin): Handle masked shifts
	even if the mask is not all ones.

	* gcc.target/i386/pr85323-7.c: New test.
	* gcc.target/i386/pr85323-8.c: New test.
	* gcc.target/i386/pr85323-9.c: New test.


	Jakub

Comments

Kirill Yukhin May 17, 2018, 5:15 a.m. | #1
Hello Jakub,
On 11 мая 10:10, Jakub Jelinek wrote:
> Hi!
> 
> On top of the earlier 3 pending patches, this patch adds constant folding
> of the shifts even when the mask is not all ones (as long as the orig value
> argument is VECTOR_CST too).  Then we can just do the blend according to the
> constant mask.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Patch is OK for main trunk.

--
Thanks, K

Patch

--- gcc/config/i386/i386.c.jj	2018-05-10 20:00:00.826748252 +0200
+++ gcc/config/i386/i386.c	2018-05-10 22:36:27.865796372 +0200
@@ -33365,6 +33365,7 @@  ix86_fold_builtin (tree fndecl, int n_ar
 				   DECL_FUNCTION_CODE (fndecl);
       enum rtx_code rcode;
       bool is_vshift;
+      unsigned HOST_WIDE_INT mask;
 
       switch (fn_code)
 	{
@@ -33708,17 +33709,21 @@  ix86_fold_builtin (tree fndecl, int n_ar
 	  gcc_assert (n_args >= 2);
 	  if (TREE_CODE (args[0]) != VECTOR_CST)
 	    break;
+	  mask = HOST_WIDE_INT_M1U;
 	  if (n_args > 2)
 	    {
-	      /* This is masked shift.  Only optimize if the mask is all
-		 ones.  */
+	      /* This is masked shift.  */
 	      if (!tree_fits_uhwi_p (args[n_args - 1])
 		  || TREE_SIDE_EFFECTS (args[n_args - 2]))
 		break;
-	      unsigned HOST_WIDE_INT mask = tree_to_uhwi (args[n_args - 1]);
+	      mask = tree_to_uhwi (args[n_args - 1]);
 	      unsigned elems = TYPE_VECTOR_SUBPARTS (TREE_TYPE (args[0]));
-	      if ((mask | (HOST_WIDE_INT_M1U << elems)) != HOST_WIDE_INT_M1U)
+	      mask |= HOST_WIDE_INT_M1U << elems;
+	      if (mask != HOST_WIDE_INT_M1U
+		  && TREE_CODE (args[n_args - 2]) != VECTOR_CST)
 		break;
+	      if (mask == (HOST_WIDE_INT_M1U << elems))
+		return args[n_args - 2];
 	    }
 	  if (is_vshift && TREE_CODE (args[1]) != VECTOR_CST)
 	    break;
@@ -33726,17 +33731,25 @@  ix86_fold_builtin (tree fndecl, int n_ar
 			  : ix86_vector_shift_count (args[1])))
 	    {
 	      unsigned HOST_WIDE_INT count = tree_to_uhwi (tem);
-	      if (count == 0)
+	      unsigned HOST_WIDE_INT prec
+		= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0])));
+	      if (count == 0 && mask == HOST_WIDE_INT_M1U)
 		return args[0];
-	      if (count >= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0]))))
+	      if (count >= prec)
 		{
-		  if (rcode != ASHIFTRT)
+		  if (rcode == ASHIFTRT)
+		    count = prec - 1;
+		  else if (mask == HOST_WIDE_INT_M1U)
 		    return build_zero_cst (TREE_TYPE (args[0]));
-		  count = TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0]))) - 1;
 		}
 	      tree countt = NULL_TREE;
 	      if (!is_vshift)
-		countt = build_int_cst (integer_type_node, count);
+		{
+		  if (count >= prec)
+		    countt = integer_zero_node;
+		  else
+		    countt = build_int_cst (integer_type_node, count);
+		}
 	      tree_vector_builder builder;
 	      builder.new_unary_operation (TREE_TYPE (args[0]), args[0],
 					   false);
@@ -33755,8 +33768,6 @@  ix86_fold_builtin (tree fndecl, int n_ar
 		      if (TREE_CODE (countt) != INTEGER_CST
 			  || TREE_OVERFLOW (countt))
 			return NULL_TREE;
-		      int prec
-			= TYPE_PRECISION (TREE_TYPE (TREE_TYPE (args[0])));
 		      if (wi::neg_p (wi::to_wide (countt))
 			  || wi::to_widest (countt) >= prec)
 			{
@@ -33770,6 +33781,8 @@  ix86_fold_builtin (tree fndecl, int n_ar
 			    }
 			}
 		    }
+		  else if (count >= prec)
+		    elt = build_zero_cst (TREE_TYPE (elt));
 		  elt = const_binop (rcode == ASHIFT
 				     ? LSHIFT_EXPR : RSHIFT_EXPR,
 				     TREE_TYPE (elt), elt, countt);
@@ -33777,6 +33790,13 @@  ix86_fold_builtin (tree fndecl, int n_ar
 		    return NULL_TREE;
 		  if (rcode == LSHIFTRT)
 		    elt = fold_convert (type, elt);
+		  if ((mask & (HOST_WIDE_INT_1U << i)) == 0)
+		    {
+		      elt = VECTOR_CST_ELT (args[n_args - 2], i);
+		      if (TREE_CODE (elt) != INTEGER_CST
+			  || TREE_OVERFLOW (elt))
+			return NULL_TREE;
+		    }
 		  builder.quick_push (elt);
 		}
 	      return builder.build ();
--- gcc/testsuite/gcc.target/i386/pr85323-7.c.jj	2018-05-10 22:16:54.928522920 +0200
+++ gcc/testsuite/gcc.target/i386/pr85323-7.c	2018-05-10 22:18:32.071623808 +0200
@@ -0,0 +1,173 @@ 
+/* PR target/85323 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl -mavx512bw -fdump-tree-optimized" } */
+
+#include <x86intrin.h>
+
+struct S1 { __m128i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s1;
+struct S2 { __m256i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s2;
+struct S3 { __m512i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s3;
+
+/* { dg-final { scan-tree-dump-times "s1.a = \{ -1288052729488364305, -761680639942076944 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.b = \{ -1288052733496000504, -1522798334733798464 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.c = \{ -7953098707027088688, -1522798335701756432 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.d = \{ 2295775699285163865, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.e = \{ 2295594821821115631, 1729384592029035499 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.f = \{ 164076671622753519, 2005535449970158571 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.g = \{ -1288052729488364305, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.h = \{ -10248187392578321, -576458420098004273 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.i = \{ 164076675361909999, -1522798334225615017 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.j = \{ -1288615670851851040, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.k = \{ -2623536994447282961, 597999838079979 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.l = \{ -8286618362551751441, -1522854662460362880 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.m = \{ -1288052729488364305, 125356960816430453 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.n = \{ 71737335514923008, -1522798337175964586 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.o = \{ 2791509703306479, 31506487170564189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.p = \{ -78650858816642, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.q = \{ -1288052729202081792, -1522798337177008502 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.r = \{ 258238916329471, -1522798332882190337 \};" 1 "optimized" } } */
+
+void
+foo (void)
+{
+  __m128i a = _mm_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL);
+  __m128i b = _mm_set1_epi64x (3);
+  __m128i c = _mm_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U);
+  __m128i d = _mm_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+			     0x1234, 0x0012, 0x8001, 0xa55a);
+  __m128i e = _mm_set_epi64x (0xeaddeefbafecabebULL, 0xee1feaddeedfacefULL);
+  s1.a = _mm_mask_sll_epi64 (e, 0x2, a, b);
+  s1.b = _mm_mask_sll_epi32 (e, 0x5, c, b);
+  s1.c = _mm_mask_sll_epi16 (e, 0x3b, d, b);
+  s1.d = _mm_mask_srl_epi64 (e, 0x1, a, b);
+  s1.e = _mm_mask_srl_epi32 (e, 0xa, c, b);
+  s1.f = _mm_mask_srl_epi16 (e, 0xca, d, b);
+  s1.g = _mm_mask_sra_epi64 (e, 0, a, b);
+  s1.h = _mm_mask_sra_epi32 (e, 0xe, c, b);
+  s1.i = _mm_mask_sra_epi16 (e, 0x18, d, b);
+  s1.j = _mm_mask_slli_epi64 (e, 0x1, a, 4);
+  s1.k = _mm_mask_slli_epi32 (e, 0xa, c, 5);
+  s1.l = _mm_mask_slli_epi16 (e, 0x7c, d, 6);
+  s1.m = _mm_mask_srli_epi64 (e, 0x2, a, 7);
+  s1.n = _mm_mask_srli_epi32 (e, 0x7, c, 8);
+  s1.o = _mm_mask_srli_epi16 (e, 0x9a, d, 9);
+  s1.p = _mm_mask_srai_epi64 (e, 0x1, a, 10);
+  s1.q = _mm_mask_srai_epi32 (e, 0x5, c, 11);
+  s1.r = _mm_mask_srai_epi16 (e, 0x39, d, 17);
+}
+
+/* { dg-final { scan-tree-dump-times "s2.a = \{ 3771334344009719049, -2171106659920117469, -1288615670851851040, -1523361279884153888 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.b = \{ -5770329518966239232, -2171106659636823408, -1311768495219823377, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.c = \{ 504495724104253440, 7458152293351424512, -1288052733494930016, -1522798334225634336 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.d = \{ 71737338064426034, 81985529216486895, -1288052729488364305, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.e = \{ 914208372271488265, 1002855686284640547, -1288052733361782784, 864692295342795755 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.f = \{ 3771334344009711616, 389471199457902883, 82167457139067477, -1523047981938439253 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.g = \{ 3771334344009719049, 81985529216486895, -1288052729488364305, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.h = \{ 3771334340789735696, -150065818322206429, -1288052729335250944, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.i = \{ -574357824626688000, 389554409618145571, 82167457292266735, -1522798332937765973 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.j = \{ 9182379272246532360, -7952596333999229056, -644307835425925520, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.k = \{ 6906085038961335561, -3046722664757853917, -2623536998454919136, -1522798335993655552 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.l = \{ 2017701421845978377, -2171106659920115712, -8286365079448824192, -6106618329958666368 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.m = \{ 3771334344009719049, 10248191152060861, -1288052729488364305, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.n = \{ 3771334340789670161, 62678480377741603, 71737335514923008, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.o = \{ 3771334344009711616, 12103754718314787, 2791509703262290, 31506484225747947 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.p = \{ 1120895907256656, -2171106659920117469, -1288052729488364305, -2344778407428178 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.q = \{ -1864947814366686, -2171106663912571463, -1288052729202081792, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.r = \{ -281474976703223, 191310728200483, 258238916329471, -1522798334225612801 \};" 1 "optimized" } } */
+
+void
+bar (void)
+{
+  __m256i a = _mm256_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				 0x123456789abcdef0ULL, 0x0fedcba987654321ULL);
+  __m128i b = _mm_set1_epi64x (4);
+  __m256i c = _mm256_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U);
+  __m256i d = _mm256_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0);
+  __m256i e = _mm256_set_epi64x (0xeaddeefbafecabebULL, 0xee1feaddeedfacefULL,
+				 0xe1deadfeedfa0123ULL, 0x3456789abfee1d09ULL);
+  s2.a = _mm256_mask_sll_epi64 (e, 0xc, a, b);
+  s2.b = _mm256_mask_sll_epi32 (e, 0x27, c, b);
+  s2.c = _mm256_mask_sll_epi16 (e, 0x139f, d, b);
+  s2.d = _mm256_mask_srl_epi64 (e, 0x3, a, b);
+  s2.e = _mm256_mask_srl_epi32 (e, 0x9a, c, b);
+  s2.f = _mm256_mask_srl_epi16 (e, 0x79a1, d, b);
+  s2.g = _mm256_mask_sra_epi64 (e, 0xa, a, b);
+  s2.h = _mm256_mask_sra_epi32 (e, 0x19, c, b);
+  s2.i = _mm256_mask_sra_epi16 (e, 0x3acb, d, b);
+  s2.j = _mm256_mask_slli_epi64 (e, 0x7, a, 3);
+  s2.k = _mm256_mask_slli_epi32 (e, 0x7a, c, 5);
+  s2.l = _mm256_mask_slli_epi16 (e, 0x9b1c, d, 6);
+  s2.m = _mm256_mask_srli_epi64 (e, 0x2, a, 7);
+  s2.n = _mm256_mask_srli_epi32 (e, 0x39, c, 8);
+  s2.o = _mm256_mask_srli_epi16 (e, 0xabe1, d, 9);
+  s2.p = _mm256_mask_srai_epi64 (e, 0x9, a, 10);
+  s2.q = _mm256_mask_srai_epi32 (e, 0x17, c, 11);
+  s2.r = _mm256_mask_srai_epi16 (e, 0x19ae, d, 17);
+}
+
+/* { dg-final { scan-tree-dump-times "s3.a = \{ -7817839361497542344, 5083102811422187008, -2401053089206453570, -2577231341703702080, -163971058432973792, -2171106659920117469, -1288052729488364305, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.b = \{ 597998948012344, -3046722665344746818, 5083102728347975712, 3989547399, 6906085038961335561, -3046722664493648608, -1288052733496000480, 597999838079979 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.c = \{ -3053196591608342592, 1008991448208554686, -2458860116837877058, 162353514901690304, 1008991450021363712, -3530630797700628189, 5080062853577223407, -3053196590263281728 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.d = \{ -7817839361497542344, -80538480299558210, -2401053089206453570, 1147797410748803463, 35868669032213017, 40992764608243447, 573943924821290966, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.e = \{ 432346146109608248, 501427841262775799, 40992761372999680, 8351325, 457104185598287113, 501427845138612515, -1288052729488364305, 432346144057696947 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.f = \{ 501313492043125048, 289078280015054423, 430022223224748734, 4402036058503, 289078280015060233, 194690515457212545, 41072106598870255, 501554302269457877 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.g = \{ -75032909037701675, -80538480299558210, -2401053089206453570, 1147797410748803463, 35868669032213017, -2171106659920117469, -1288052729488364305, -75032909037701675 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.h = \{ -144114606193815240, -75032907751703874, 40992764711582398, 1147797406767607389, 3771334340789700744, -75032907164810973, -1288052729268142080, -144114605303747605 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.i = \{ -74874577215860424, -287382472288305577, -2401053089206436105, 223930699480533, 3771205216902578176, -2171106659635101567, 41072110759619823, -1522781857415451669 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.j = \{ -761680639942076944, -80538480299558210, 9182379272246532360, 1147797410748803463, 3771334344009719049, -2171106659920117469, -1288052729488364305, -761680639942076944 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.k = \{ -7817839363541102592, -80538480299558210, -2401053092612145136, 3989547399, -5770329515764081399, -2171106659636823408, -1288052729488364305, 299001394801643 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.l = \{ -6106752978073464520, -80694529937588352, -2401052466905826626, 1147573758916800384, 3771290526753365257, -2171106660758583296, -1288052733491761937, -1522813727388422272 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.m = \{ -7817839361497542344, 10248191152060861, -2401053089206453570, 1147797410748803463, 8967167258053254, -2171106659920117469, -1288052729488364305, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.n = \{ 54043266309378360, -80538483690656322, -2401053092603756544, 1147797406760299979, 3771334344009719049, -2171106663911658037, 71737335514923008, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.o = \{ 31244130443415864, 18014616663490661, 26740559984900798, 223926716530781, 18147001330375945, 12294734424440840, 2791513706704111, -1523060690952847267 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.p = \{ -7817839361497542344, -80538480299558210, -2401053089206453570, 1147797410748803463, 1120895907256656, 1281023894007607, -78650858816642, -2344778407428178 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.q = \{ -7817839363558997470, -80538480299558210, 640511878544062, 1147797410748803463, -1864947814366686, -2171106659920117469, -1288052729488364305, -1522813730339797366 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.r = \{ -7817839359264075464, -80538483705184257, -2400981552231171394, 1147854954720657407, 3771201737969376521, -2171016495369355264, 258238916308207, -34103383752705 \};" 1 "optimized" } } */
+
+void
+baz (void)
+{
+  __m512i a = _mm512_set_epi64 (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				0x123456789abcdef0ULL, 0x0fedcba987654321ULL,
+				0xfee1deadfeedfaceULL, 0x0fedcba987654321ULL,
+				0x123456789abcdef0ULL, 0xdeadbeefcafebabeULL);
+  __m128i b = _mm_set1_epi64x (5);
+  __m512i c = _mm512_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U,
+				0, 0x0fedcba9U, 0x12345678U, 0x80000001U,
+				0xdeadbeefU, 0xdeadbeefU, 0xc00010ffU, 0x00111100U);
+  __m512i d = _mm512_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0,
+				0x0012, 0x8001, 0xcafe, 0xbabe,
+				0xbeef, 0xcafe, 0x9abc, 0xdef0,
+				0x8070, 0x6543, 0x129f, 0xcafe,
+				0xdead, 0xbeef, 0xcafe, 0xbabe);
+  __m512i e = _mm512_set_epi64 (0xeadde0fbafecabebULL, 0xee1feaddeedfacefULL,
+				0xe1deadfeedfa0123ULL, 0x3456789abfee1d09ULL,
+				0x0fedcba9edcba987ULL, 0xdeadbeefcafebabeULL,
+				0xfee1deadcafebabeULL, 0x938174857adf5138ULL);
+  s3.a = _mm512_mask_sll_epi64 (e, 0x1a, a, b);
+  s3.b = _mm512_mask_sll_epi32 (e, 0x9eba, c, b);
+  s3.c = _mm512_mask_sll_epi16 (e, 0xdeadbeefU, d, b);
+  s3.d = _mm512_mask_srl_epi64 (e, 0x70, a, b);
+  s3.e = _mm512_mask_srl_epi32 (e, 0xcafe, c, b);
+  s3.f = _mm512_mask_srl_epi16 (e, 0xbabecafeU, d, b);
+  s3.g = _mm512_mask_sra_epi64 (e, 0x91, a, b);
+  s3.h = _mm512_mask_sra_epi32 (e, 0x996a, c, b);
+  s3.i = _mm512_mask_sra_epi16 (e, 0x6a3791feU, d, b);
+  s3.j = _mm512_mask_slli_epi64 (e, 0x85, a, 3);
+  s3.k = _mm512_mask_slli_epi32 (e, 0x8691, c, 4);
+  s3.l = _mm512_mask_slli_epi16 (e, 0x12345678U, d, 6);
+  s3.m = _mm512_mask_srli_epi64 (e, 0x12, a, 7);
+  s3.n = _mm512_mask_srli_epi32 (e, 0x3456, c, 8);
+  s3.o = _mm512_mask_srli_epi16 (e, 0x789abcdeU, d, 9);
+  s3.p = _mm512_mask_srai_epi64 (e, 0xf0, a, 10);
+  s3.q = _mm512_mask_srai_epi32 (e, 0x4321, c, 11);
+  s3.r = _mm512_mask_srai_epi16 (e, 0x98765432U, d, 17);
+}
--- gcc/testsuite/gcc.target/i386/pr85323-8.c.jj	2018-05-10 22:23:04.478906714 +0200
+++ gcc/testsuite/gcc.target/i386/pr85323-8.c	2018-05-10 22:23:17.167919891 +0200
@@ -0,0 +1,166 @@ 
+/* PR target/85323 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl -mavx512bw -fdump-tree-optimized" } */
+
+#include <x86intrin.h>
+
+struct S1 { __m128i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s1;
+struct S2 { __m256i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s2;
+struct S3 { __m512i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s3;
+
+/* { dg-final { scan-tree-dump-times "s1.a = \{ 0, -761680639942076944 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.b = \{ 8, 2443359168 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.c = \{ -7953356941935760688, 1475401200 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.d = \{ 2295775699285163865, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.e = \{ 2295594817813479424, 1729384589077512192 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.f = \{ 163818436714037248, 2005535447018635264 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.g = \{ 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.h = \{ -10248191400214528, -576458420098004273 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.i = \{ 163818436445601792, 63319 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.j = \{ -1288615670851851040, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.k = \{ -2623536998454919168, 597996886556672 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.l = \{ -8286618366559387648, 206436520996736 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.m = \{ 0, 125356960816430453 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.n = \{ 71737335514923008, 1193046 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.o = \{ 2533274794590208, 31243722414882909 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.p = \{ -78650858816642, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.q = \{ 4293918720, 149130 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.r = \{ 65535, 4294967295 \};" 1 "optimized" } } */
+
+void
+foo (void)
+{
+  __m128i a = _mm_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL);
+  __m128i b = _mm_set1_epi64x (3);
+  __m128i c = _mm_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U);
+  __m128i d = _mm_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+			     0x1234, 0x0012, 0x8001, 0xa55a);
+  s1.a = _mm_maskz_sll_epi64 (0x2, a, b);
+  s1.b = _mm_maskz_sll_epi32 (0x5, c, b);
+  s1.c = _mm_maskz_sll_epi16 (0x3b, d, b);
+  s1.d = _mm_maskz_srl_epi64 (0x1, a, b);
+  s1.e = _mm_maskz_srl_epi32 (0xa, c, b);
+  s1.f = _mm_maskz_srl_epi16 (0xca, d, b);
+  s1.g = _mm_maskz_sra_epi64 (0, a, b);
+  s1.h = _mm_maskz_sra_epi32 (0xe, c, b);
+  s1.i = _mm_maskz_sra_epi16 (0x18, d, b);
+  s1.j = _mm_maskz_slli_epi64 (0x1, a, 4);
+  s1.k = _mm_maskz_slli_epi32 (0xa, c, 5);
+  s1.l = _mm_maskz_slli_epi16 (0x7c, d, 6);
+  s1.m = _mm_maskz_srli_epi64 (0x2, a, 7);
+  s1.n = _mm_maskz_srli_epi32 (0x7, c, 8);
+  s1.o = _mm_maskz_srli_epi16 (0x9a, d, 9);
+  s1.p = _mm_maskz_srai_epi64 (0x1, a, 10);
+  s1.q = _mm_maskz_srai_epi32 (0x5, c, 11);
+  s1.r = _mm_maskz_srai_epi16 (0x39, d, 17);
+}
+
+/* { dg-final { scan-tree-dump-times "s2.a = \{ 0, 0, -1288615670851851040, -1523361279884153888 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.b = \{ -5770329518966239232, 4275878544, -1311768499227459584, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.c = \{ 504495724104253440, 7457960982925541888, 1070496, 44000 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.d = \{ 71737338064426034, 81985529216486895, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.e = \{ 914208369051435008, 1002855682292056064, 134217728, 864692292391272448 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.f = \{ 0, 389279893024604160, 81909218222803541, 13117042920363 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.g = \{ 0, 81985529216486895, 0, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.h = \{ 69904, -150065822314790912, 4160749568, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.i = \{ -574490427446984704, 389554405625561088, 81909222383550464, 4239391659 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.j = \{ 9182379272246532360, -7952596333999229056, -644307835425925520, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.k = \{ 6906085035741282304, -3046722668750438400, -2623536998454919136, 1183502080 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.l = \{ 2017701418625925120, 2048, -8286623314357496192, -6106881094714347648 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.m = \{ 0, 10248191152060861, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.n = \{ 4369, 62678476385157120, 71737335514923008, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.o = \{ 0, 12103754718314496, 2533274794590290, 31243722421501952 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.p = \{ 1120895907256656, 0, 0, -2344778407428178 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.q = \{ -1864947814366686, 130489, 4293918720, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.r = \{ -281474976710656, 4294901760, 65535, 65535 \};" 1 "optimized" } } */
+
+void
+bar (void)
+{
+  __m256i a = _mm256_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				 0x123456789abcdef0ULL, 0x0fedcba987654321ULL);
+  __m128i b = _mm_set1_epi64x (4);
+  __m256i c = _mm256_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U);
+  __m256i d = _mm256_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0);
+  s2.a = _mm256_maskz_sll_epi64 (0xc, a, b);
+  s2.b = _mm256_maskz_sll_epi32 (0x27, c, b);
+  s2.c = _mm256_maskz_sll_epi16 (0x139f, d, b);
+  s2.d = _mm256_maskz_srl_epi64 (0x3, a, b);
+  s2.e = _mm256_maskz_srl_epi32 (0x9a, c, b);
+  s2.f = _mm256_maskz_srl_epi16 (0x79a1, d, b);
+  s2.g = _mm256_maskz_sra_epi64 (0xa, a, b);
+  s2.h = _mm256_maskz_sra_epi32 (0x19, c, b);
+  s2.i = _mm256_maskz_sra_epi16 (0x3acb, d, b);
+  s2.j = _mm256_maskz_slli_epi64 (0x7, a, 3);
+  s2.k = _mm256_maskz_slli_epi32 (0x7a, c, 5);
+  s2.l = _mm256_maskz_slli_epi16 (0x9b1c, d, 6);
+  s2.m = _mm256_maskz_srli_epi64 (0x2, a, 7);
+  s2.n = _mm256_maskz_srli_epi32 (0x39, c, 8);
+  s2.o = _mm256_maskz_srli_epi16 (0xabe1, d, 9);
+  s2.p = _mm256_maskz_srai_epi64 (0x9, a, 10);
+  s2.q = _mm256_maskz_srai_epi32 (0x17, c, 11);
+  s2.r = _mm256_maskz_srai_epi16 (0x19ae, d, 17);
+}
+
+/* { dg-final { scan-tree-dump-times "s3.a = \{ 0, 5083102811422187008, 0, -2577231341703702080, -163971058432973792, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.b = \{ 597996886556672, -3046722668750438400, 5083102728347975712, 0, 6906085035741282304, -3046722664493648608, 32, 597996886556672 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.c = \{ -3053196591608342592, 1008991448208506880, -2458860116837924864, 162129588191778752, 1008991446801317888, -3530822104133926912, 5080062853577179136, -3053196593214761024 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.d = \{ 0, 0, 0, 0, 35868669032213017, 40992764608243447, 573943924821290966, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.e = \{ 432346144048152576, 501427841262775799, 40992761372999680, 8351325, 457104182378233856, 501427841146028032, 0, 432346144057696947 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.f = \{ 501313492043104256, 289078280015054423, 429812289518239744, 4398046511104, 289078280015052800, 194499209023914113, 40813871690153984, 501306933628044757 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.g = \{ -75032909037701675, 0, 0, 0, 35868669032213017, 0, 0, -75032909037701675 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.h = \{ -144114608255270912, -75032911157395456, 40992761305890816, 8351325, 34952, -75032911157395456, 4227858432, -144114608255270912 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.i = \{ -74874577215881216, -287382472288305577, 65271, 64981, 3478933209088, 4277600385, 40813875850903552, 279241565863936 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.j = \{ -761680639942076944, 0, 9182379272246532360, 0, 0, 0, 0, -761680639942076944 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.k = \{ 17895424, 0, 16, 0, -5770329518984134656, 4275878544, 0, 298998443278336 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.l = \{ -6106881094714392576, 88788378369920, 210559412731904, 274877951872, 88785563942912, 3154118656, 4194304, 44928 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.m = \{ 0, 10248191152060861, 0, 0, 8967167258053254, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.n = \{ 54043264247922688, 14593470, 8388608, 1043915, 0, 1043915, 71737335514923008, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.o = \{ 31244130443395072, 18014613257846885, 26740556579209216, 6619229, 18014398510071808, 12103423998558216, 2533274790395904, 408028512349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.p = \{ 0, 0, 0, 0, 1120895907256656, 1281023894007607, -78650858816642, -2344778407428178 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.q = \{ 546, 0, 640508472852480, 0, -1864947814366686, 0, 0, 149130 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.r = \{ 4294901760, 65535, 281470681743360, 281470681808895, 0, 281474976645120, 0, -281474976645121 \};" 1 "optimized" } } */
+
+void
+baz (void)
+{
+  __m512i a = _mm512_set_epi64 (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				0x123456789abcdef0ULL, 0x0fedcba987654321ULL,
+				0xfee1deadfeedfaceULL, 0x0fedcba987654321ULL,
+				0x123456789abcdef0ULL, 0xdeadbeefcafebabeULL);
+  __m128i b = _mm_set1_epi64x (5);
+  __m512i c = _mm512_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U,
+				0, 0x0fedcba9U, 0x12345678U, 0x80000001U,
+				0xdeadbeefU, 0xdeadbeefU, 0xc00010ffU, 0x00111100U);
+  __m512i d = _mm512_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0,
+				0x0012, 0x8001, 0xcafe, 0xbabe,
+				0xbeef, 0xcafe, 0x9abc, 0xdef0,
+				0x8070, 0x6543, 0x129f, 0xcafe,
+				0xdead, 0xbeef, 0xcafe, 0xbabe);
+  s3.a = _mm512_maskz_sll_epi64 (0x1a, a, b);
+  s3.b = _mm512_maskz_sll_epi32 (0x9eba, c, b);
+  s3.c = _mm512_maskz_sll_epi16 (0xdeadbeefU, d, b);
+  s3.d = _mm512_maskz_srl_epi64 (0x70, a, b);
+  s3.e = _mm512_maskz_srl_epi32 (0xcafe, c, b);
+  s3.f = _mm512_maskz_srl_epi16 (0xbabecafeU, d, b);
+  s3.g = _mm512_maskz_sra_epi64 (0x91, a, b);
+  s3.h = _mm512_maskz_sra_epi32 (0x996a, c, b);
+  s3.i = _mm512_maskz_sra_epi16 (0x6a3791feU, d, b);
+  s3.j = _mm512_maskz_slli_epi64 (0x85, a, 3);
+  s3.k = _mm512_maskz_slli_epi32 (0x8691, c, 4);
+  s3.l = _mm512_maskz_slli_epi16 (0x12345678U, d, 6);
+  s3.m = _mm512_maskz_srli_epi64 (0x12, a, 7);
+  s3.n = _mm512_maskz_srli_epi32 (0x3456, c, 8);
+  s3.o = _mm512_maskz_srli_epi16 (0x789abcdeU, d, 9);
+  s3.p = _mm512_maskz_srai_epi64 (0xf0, a, 10);
+  s3.q = _mm512_maskz_srai_epi32 (0x4321, c, 11);
+  s3.r = _mm512_maskz_srai_epi16 (0x98765432U, d, 17);
+}
--- gcc/testsuite/gcc.target/i386/pr85323-9.c.jj	2018-05-10 22:34:39.767685478 +0200
+++ gcc/testsuite/gcc.target/i386/pr85323-9.c	2018-05-10 22:35:16.566724403 +0200
@@ -0,0 +1,180 @@ 
+/* PR target/85323 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl -mavx512bw -fdump-tree-optimized" } */
+
+#include <x86intrin.h>
+
+struct S1 { __m128i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s1;
+struct S2 { __m256i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s2;
+struct S3 { __m512i a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r; } s3;
+
+/* { dg-final { scan-tree-dump-times "s1.a = \{ -1288052729488364305, -761680639942076944 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.b = \{ -1288052733479223296, -1522798337177157632 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.c = \{ 2623605017854121320, -1522798337177100288 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.d = \{ 35871495301330685, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.e = \{ 4007636207, 1729384592029035499 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.f = \{ 656094930711653615, 2005509212014947307 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.g = \{ -1288052729488364305, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.h = \{ -287331089, -576458420136181760 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.i = \{ 656094934652136687, -1522798334225612805 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.j = \{ -4342213319840130048, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.k = \{ 0, 149499221639168 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.l = \{ 2623346860252725248, 57344 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.m = \{ 0, 2005711373062887255 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.n = \{ 128, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.o = \{ 655836695802937344, 2005509209063424011 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.p = \{ -157301717633283, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.q = \{ 4294967168, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s1.r = \{ 655836695735888214, 4294967291 \};" 1 "optimized" } } */
+
+void
+foo (void)
+{
+  __m128i a = _mm_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL);
+  __m128i b = _mm_set_epi64x (3, 9);
+  __m128i c = _mm_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U);
+  __m128i d = _mm_set_epi32 (3, 32, -6, 24);
+  __m128i e = _mm_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+			     0x1234, 0x0012, 0x8001, 0xa55a);
+  __m128i f = _mm_set_epi16 (3, 16, -1, 12, 1, 0, 5, 2);
+  __m128i g = _mm_set_epi64x (0xeaddeefbafecabebULL, 0xee1feaddeedfacefULL);
+  s1.a = _mm_mask_sllv_epi64 (g, 0x2, a, b);
+  s1.b = _mm_mask_sllv_epi32 (g, 0x5, c, d);
+  s1.c = _mm_mask_sllv_epi16 (g, 0x3b, e, f);
+  s1.d = _mm_mask_srlv_epi64 (g, 0x1, a, b);
+  s1.e = _mm_mask_srlv_epi32 (g, 0xa, c, d);
+  s1.f = _mm_mask_srlv_epi16 (g, 0xca, e, f);
+  s1.g = _mm_mask_srav_epi64 (g, 0, a, b);
+  s1.h = _mm_mask_srav_epi32 (g, 0xe, c, d);
+  s1.i = _mm_mask_srav_epi16 (g, 0x18, e, f);
+  s1.j = _mm_maskz_sllv_epi64 (0x1, a, b);
+  s1.k = _mm_maskz_sllv_epi32 (0xa, c, d);
+  s1.l = _mm_maskz_sllv_epi16 (0x7c, e, f);
+  s1.m = _mm_maskz_srlv_epi64 (0x2, a, b);
+  s1.n = _mm_maskz_srlv_epi32 (0x7, c, d);
+  s1.o = _mm_maskz_srlv_epi16 (0x9a, e, f);
+  s1.p = _mm_maskz_srav_epi64 (0x1, a, b);
+  s1.q = _mm_maskz_srav_epi32 (0x5, c, d);
+  s1.r = _mm_maskz_srav_epi16 (0x39, e, f);
+}
+
+/* { dg-final { scan-tree-dump-times "s2.a = \{ 3771334344009719049, -2171106659920117469, 0, -1523361279884153888 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.b = \{ 9177596069264525312, -2171106662061094912, -81985527194080017, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.c = \{ 1008895103428722688, -5985092594349506048, -1288052733493865112, -1522798334225620992 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.d = \{ 2189249818860, 0, -1288052729488364305, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.e = \{ 114276047740869897, 3992584483, -1288052733496000512, 3377706967018475 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.f = \{ 3771334344009711616, 3115556349134373155, 656094934652102998, -1523061098981359605 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.g = \{ 3771334344009719049, 0, -1288052729488364305, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.h = \{ 3771334340789805600, -302382813, -1288052729201033217, -1522798334225634325 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.i = \{ -287253348398858240, 3115618685519790371, 656094934872403183, -1522798332882190341 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.j = \{ 6722813395751927808, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.k = \{ 9177596069255577600, 0, -81985531201716224, 610839792 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.l = \{ 1008895102094934016, 512, 2623346782945449320, -763360136839241728 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.m = \{ 0, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.n = \{ 139808, 0, -81985531201716224, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.o = \{ 0, 3115407575762206720, 655836695802947926, 2005509209063424000 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.p = \{ 2189249818860, 0, 0, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.q = \{ -29839143554899424, 130489, 4294967295, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s2.r = \{ -287384211757400064, 3115365046459170816, 655836695735888214, 65531 \};" 1 "optimized" } } */
+
+void
+bar (void)
+{
+  __m256i a = _mm256_set_epi64x (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				 0x123456789abcdef0ULL, 0x0fedcba987654321ULL);
+  __m256i b = _mm256_set_epi64x (4, 65, -2, 19);
+  __m256i c = _mm256_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U);
+  __m256i d = _mm256_set_epi32 (12, 1, 0, -2, 32, 11, 7, 3);
+  __m256i e = _mm256_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0);
+  __m256i f = _mm256_set_epi16 (3, 16, -1, 12, 1, 0, 5, 2, 1, 2, 3, 4, 5, 6, 7, 8);
+  __m256i g = _mm256_set_epi64x (0xeaddeefbafecabebULL, 0xee1feaddeedfacefULL,
+				 0xe1deadfeedfa0123ULL, 0x3456789abfee1d09ULL);
+  s2.a = _mm256_mask_sllv_epi64 (g, 0xc, a, b);
+  s2.b = _mm256_mask_sllv_epi32 (g, 0x27, c, d);
+  s2.c = _mm256_mask_sllv_epi16 (g, 0x139f, e, f);
+  s2.d = _mm256_mask_srlv_epi64 (g, 0x3, a, b);
+  s2.e = _mm256_mask_srlv_epi32 (g, 0x9a, c, d);
+  s2.f = _mm256_mask_srlv_epi16 (g, 0x79a1, e, f);
+  s2.g = _mm256_mask_srav_epi64 (g, 0xa, a, b);
+  s2.h = _mm256_mask_srav_epi32 (g, 0x19, c, d);
+  s2.i = _mm256_mask_srav_epi16 (g, 0x3acb, e, f);
+  s2.j = _mm256_maskz_sllv_epi64 (0x7, a, b);
+  s2.k = _mm256_maskz_sllv_epi32 (0x7a, c, d);
+  s2.l = _mm256_maskz_sllv_epi16 (0x9b1c, e, f);
+  s2.m = _mm256_maskz_srlv_epi64 (0x2, a, b);
+  s2.n = _mm256_maskz_srlv_epi32 (0x39, c, d);
+  s2.o = _mm256_maskz_srlv_epi16 (0xabe1, e, f);
+  s2.p = _mm256_maskz_srav_epi64 (0x9, a, b);
+  s2.q = _mm256_maskz_srav_epi32 (0x17, c, d);
+  s2.r = _mm256_maskz_srav_epi16 (0x19ae, e, f);
+}
+
+/* { dg-final { scan-tree-dump-times "s3.a = \{ -7817839361497542344, 5247073869855161280, -2401053089206453570, -161076958856481380, 6722813395751927808, -2171106659920117469, -1288052729488364305, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.b = \{ -4611667328963227336, 6592669524527332030, 2541551364173987968, 3989547399, 9177596072475630857, 1851607040, -1288052733496000512, 76543604430777323 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.c = \{ 6233191819462621886, 8070591269736331966, 8610979175836203710, 40756324093949308, 1008895105314979840, -5985092594189729501, 2623346860254866671, -763360133887762432 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.d = \{ -7817839361497542344, -80538480299558210, -2401053089206453570, 1147797410748803463, 2189249818860, 0, 0, -1522813727388423189 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.e = \{ -4611667328963227336, 31339239126560699, 81985526923526144, 66810602, 114276047740869897, 3992584483, -1288052729488364305, 3377704168205116 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.f = \{ 125466298768380216, 36028797018976959, 107451899833268926, 563228820875655, 289076540546030857, 3115556349134373122, 656094930711653615, 2005756577704837131 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.g = \{ -4689556814856355, -80538480299558210, -2401053089206453570, 1147797410748803463, 2189249818860, -2171106659920117469, -1288052729488364305, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.h = \{ -4611667328963227336, -4689555420693826, 81985530312440510, 1147797406826066666, 3771334340789805600, -302382813, -1288052729201033217, -1125892660352021 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.i = \{ -18648885549379272, -36028797018901825, -2401053089206435841, 786880652893535, 3771203477433548800, -2171106659687071486, 656094934872403183, -1522779624004670485 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.j = \{ 0, 5247073869855161280, 0, -161076958856481380, 6722813395751927808, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.k = \{ -4611667331024683008, 6592669521121640448, 2541551364173987968, 0, 9177596069255577600, 1851607040, 0, 76543601479254016 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.l = \{ 6233191819462621886, 8070591269736284160, 8610979175836155904, 40532397384037756, 1008895102094934016, -5985283900623028224, 2623346860254822400, -763360136839241728 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.m = \{ 0, 0, 0, 0, 2189249818860, 0, 0, 0 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.n = \{ -4611667331024683008, 31339239126560699, 81985526923526144, 66810602, 114276044520816640, 0, 0, 3377704168205116 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.o = \{ 125466298768359424, 36028797018976959, 107241966126759936, 563224831328256, 289076540546023424, 3115365042701074690, 655836695802937344, 2005509209063424011 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.p = \{ -4689556814856355, 0, 0, 0, 2189249818860, 0, 0, -150065818075403349 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.q = \{ -4611667331024683008, -4689558826385408, 81985526906748928, 66810602, 139808, -4294967296, 4294967295, -1125895611875328 \};" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "s3.r = \{ -18648885549400064, -36028797018901825, 65535, 562949953477983, 1739464179712, 4225630466, 655836699963686912, 281474976645120 \};" 1 "optimized" } } */
+
+void
+baz (void)
+{
+  __m512i a = _mm512_set_epi64 (0xdeadbeefcafebabeULL, 0xfee1deadfeedfaceULL,
+				0x123456789abcdef0ULL, 0x0fedcba987654321ULL,
+				0xfee1deadfeedfaceULL, 0x0fedcba987654321ULL,
+				0x123456789abcdef0ULL, 0xdeadbeefcafebabeULL);
+  __m512i b = _mm512_set_epi64 (4, 65, -2, 19, 1, 0, 2, 9);
+  __m512i c = _mm512_set_epi32 (0xc00010ffU, 0x12345678U, 0xfedcba98U, 0x80000001U,
+				0xdeadbeefU, 0x0fedcba9U, 0xcafebabeU, 0x00111100U,
+				0, 0x0fedcba9U, 0x12345678U, 0x80000001U,
+				0xdeadbeefU, 0xdeadbeefU, 0xc00010ffU, 0x00111100U);
+  __m512i d = _mm512_set_epi32 (12, 1, 0, -2, 32, 11, 7, 3, 1, 2, 4, 7, 9, 2, 0, 3);
+  __m512i e = _mm512_set_epi16 (0xdead, 0xbeef, 0xcafe, 0xbabe,
+				0x1234, 0x0012, 0x8001, 0xa55a,
+				0x5678, 0x9abc, 0xdef0, 0x1020,
+				0x8070, 0x6543, 0x129f, 0,
+				0x0012, 0x8001, 0xcafe, 0xbabe,
+				0xbeef, 0xcafe, 0x9abc, 0xdef0,
+				0x8070, 0x6543, 0x129f, 0xcafe,
+				0xdead, 0xbeef, 0xcafe, 0xbabe);
+  __m512i f = _mm512_set_epi16 (3, 16, -1, 12, 1, 0, 5, 2, 1, 2, 3, 4, 5, 6, 7, 8,
+				3, 9, 2, 1, 7, 3, -12, 26, 8, 15, 17, 2, 7, 0, 3, 0);
+  __m512i g = _mm512_set_epi64 (0xeadde0fbafecabebULL, 0xee1feaddeedfacefULL,
+				0xe1deadfeedfa0123ULL, 0x3456789abfee1d09ULL,
+				0x0fedcba9edcba987ULL, 0xdeadbeefcafebabeULL,
+				0xfee1deadcafebabeULL, 0x938174857adf5138ULL);
+  s3.a = _mm512_mask_sllv_epi64 (g, 0x1a, a, b);
+  s3.b = _mm512_mask_sllv_epi32 (g, 0x9eba, c, d);
+  s3.c = _mm512_mask_sllv_epi16 (g, 0xdeadbeefU, e, f);
+  s3.d = _mm512_mask_srlv_epi64 (g, 0x70, a, b);
+  s3.e = _mm512_mask_srlv_epi32 (g, 0xcafe, c, d);
+  s3.f = _mm512_mask_srlv_epi16 (g, 0xbabecafeU, e, f);
+  s3.g = _mm512_mask_srav_epi64 (g, 0x91, a, b);
+  s3.h = _mm512_mask_srav_epi32 (g, 0x996a, c, d);
+  s3.i = _mm512_mask_srav_epi16 (g, 0x6a3791feU, e, f);
+  s3.j = _mm512_maskz_sllv_epi64 (0x1a, a, b);
+  s3.k = _mm512_maskz_sllv_epi32 (0x9eba, c, d);
+  s3.l = _mm512_maskz_sllv_epi16 (0xdeadbeefU, e, f);
+  s3.m = _mm512_maskz_srlv_epi64 (0x70, a, b);
+  s3.n = _mm512_maskz_srlv_epi32 (0xcafe, c, d);
+  s3.o = _mm512_maskz_srlv_epi16 (0xbabecafeU, e, f);
+  s3.p = _mm512_maskz_srav_epi64 (0x91, a, b);
+  s3.q = _mm512_maskz_srav_epi32 (0x996a, c, d);
+  s3.r = _mm512_maskz_srav_epi16 (0x6a3791feU, e, f);
+}