<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:799957587;
        mso-list-type:hybrid;
        mso-list-template-ids:-1214880770 44585902 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Hi Chandler,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">First of all, I did not add any functional changes to AVX2. So the AVX2 code state did not change at all.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">SHUFPD is common logic for AVX2 and AVX-512 and I put it in a separate function, like you did with SHUFPS.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I worked on AVX-512 shuffles, 32 and 64-bit elements. Now the functions lowerV8X64VectorShuffle() and lowerV16X32VectorShuffle() are short and clear.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Each AVX-512 shuffle is replaced now with 1 instruction - instead of 5-6 that were before. This is the main benefit of AVX-512 - we don’t need more than one
 instruction.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The new ISA provides many instructions that shuffle 512-bit vectors. In the worst case I put an instruction with variable permutations, which loads indices
 from memory.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">In order to avoid the load, I’m trying to match PSHUFD, SHUFPS, VPERMIL, VALIGN patterns. I added a lit test for each pattern.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The work on V8X64 and V16X32 is almost completed. We also have 128-bit shuffles that will be implemented soon and may give some code improvements.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Now I need to handle v32i16 vectors - it is also a single instruction  in the worst case.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I’m going to look at your utility. ( It is still not clear for me why do we need it. )<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-left:36.0pt;text-indent:-18.0pt;mso-list:l0 level1 lfo1">
<![if !supportLists]><span style="font-family:"Calibri","sans-serif";color:#31849B"><span style="mso-list:Ignore">-<span style="font:7.0pt "Times New Roman"">         
</span></span></span><![endif]><span dir="LTR"></span><b><i><span style="color:#31849B"> Elena<o:p></o:p></span></i></b></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Chandler Carruth [mailto:chandlerc@google.com]
<br>
<b>Sent:</b> Thursday, June 04, 2015 04:59<br>
<b>To:</b> Demikhovsky, Elena; llvm-commits@cs.uiuc.edu<br>
<b>Subject:</b> Re: [llvm] r238918 - AVX-512: VSHUFPD instruction selection - code improvements<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Elena, this isn't an AVX-512 specific change, and isn't just code improvements.<o:p></o:p></p>
<div>
<p class="MsoNormal">This refactors logic to be common betwene AVX2 and AVX-512. While that may be the right call, it isn't clear what the end state looks like here, and the refactoring isn't an obvious benefit. The code for AVX2 was very simple, and the new
 code involves loops and other complexity. Perhaps we need it, but that isn't clear to me yet.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Notably, the most unclear thing to me about all of this is what the end state of the AVX-512 code looks like. I really would rather you send a precommit review for that for discussion rather than refactoring AVX2 code that we know to be
 working.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Jun 3, 2015 at 4:30 AM Elena Demikhovsky <<a href="mailto:elena.demikhovsky@intel.com">elena.demikhovsky@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-right:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">Author: delena<br>
Date: Wed Jun  3 06:21:01 2015<br>
New Revision: 238918<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238918-26view-3Drev&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=BTXejm0exaZrtAaWIMwO24qGYjKnMgiCqIPbXPCSIOI&s=yh-TXtQz713RbI9ZAktmju-exf3qj7wDiOr49Gf4Ets&e=" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=238918&view=rev</a><br>
Log:<br>
AVX-512: VSHUFPD instruction selection - code improvements<br>
<br>
Modified:<br>
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
    llvm/trunk/test/CodeGen/X86/avx512-shuffle.ll<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Target_X86_X86ISelLowering.cpp-3Frev-3D238918-26r1-3D238917-26r2-3D238918-26view-3Ddiff&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=BTXejm0exaZrtAaWIMwO24qGYjKnMgiCqIPbXPCSIOI&s=JZnALRACF22NcjOqQT-Q3y-yxuBoosaIPjamzav0dts&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=238918&r1=238917&r2=238918&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Jun  3 06:21:01 2015<br>
@@ -9468,6 +9468,37 @@ static bool isShuffleMaskInputInPlace(in<br>
   return true;<br>
 }<br>
<br>
+static SDValue lowerVectorShuffleWithSHUFPD(SDLoc DL, MVT VT,<br>
+                                            ArrayRef<int> Mask, SDValue V1,<br>
+                                            SDValue V2, SelectionDAG &DAG) {<br>
+<br>
+  // Mask for V8F64: 0/1,  8/9,  2/3,  10/11, 4/5, ..<br>
+  // Mask for V4F64; 0/1,  4/5,  2/3,  6/7..<br>
+  assert(VT.getScalarSizeInBits() == 64 && "Unexpected data type for VSHUFPD");<br>
+  int NumElts = VT.getVectorNumElements();<br>
+  bool ShufpdMask = true;<br>
+  bool CommutableMask = true;<br>
+  unsigned Immediate = 0;<br>
+  for (int i = 0; i < NumElts; ++i) {<br>
+    if (Mask[i] < 0)<br>
+      continue;<br>
+    int Val = (i & 6) + NumElts * (i & 1);<br>
+    int CommutVal = (i & 0xe) + NumElts * ((i & 1)^1);<br>
+    if (Mask[i] < Val ||  Mask[i] > Val + 1)<br>
+      ShufpdMask = false;<br>
+    if (Mask[i] < CommutVal ||  Mask[i] > CommutVal + 1)<br>
+      CommutableMask = false;<br>
+    Immediate |= (Mask[i] % 2) << i;<br>
+  }<br>
+  if (ShufpdMask)<br>
+    return DAG.getNode(X86ISD::SHUFP, DL, VT, V1, V2,<br>
+                       DAG.getConstant(Immediate, DL, MVT::i8));<br>
+  if (CommutableMask)<br>
+    return DAG.getNode(X86ISD::SHUFP, DL, VT, V2, V1,<br>
+                       DAG.getConstant(Immediate, DL, MVT::i8));<br>
+  return SDValue();<br>
+}<br>
+<br>
 /// \brief Handle lowering of 4-lane 64-bit floating point shuffles.<br>
 ///<br>
 /// Also ends up handling lowering of 4-lane 64-bit integer shuffles when AVX2<br>
@@ -9532,24 +9563,9 @@ static SDValue lowerV4F64VectorShuffle(S<br>
     return Blend;<br>
<br>
   // Check if the blend happens to exactly fit that of SHUFPD.<br>
-  if ((Mask[0] == -1 || Mask[0] < 2) &&<br>
-      (Mask[1] == -1 || (Mask[1] >= 4 && Mask[1] < 6)) &&<br>
-      (Mask[2] == -1 || (Mask[2] >= 2 && Mask[2] < 4)) &&<br>
-      (Mask[3] == -1 || Mask[3] >= 6)) {<br>
-    unsigned SHUFPDMask = (Mask[0] == 1) | ((Mask[1] == 5) << 1) |<br>
-                          ((Mask[2] == 3) << 2) | ((Mask[3] == 7) << 3);<br>
-    return DAG.getNode(X86ISD::SHUFP, DL, MVT::v4f64, V1, V2,<br>
-                       DAG.getConstant(SHUFPDMask, DL, MVT::i8));<br>
-  }<br>
-  if ((Mask[0] == -1 || (Mask[0] >= 4 && Mask[0] < 6)) &&<br>
-      (Mask[1] == -1 || Mask[1] < 2) &&<br>
-      (Mask[2] == -1 || Mask[2] >= 6) &&<br>
-      (Mask[3] == -1 || (Mask[3] >= 2 && Mask[3] < 4))) {<br>
-    unsigned SHUFPDMask = (Mask[0] == 5) | ((Mask[1] == 1) << 1) |<br>
-                          ((Mask[2] == 7) << 2) | ((Mask[3] == 3) << 3);<br>
-    return DAG.getNode(X86ISD::SHUFP, DL, MVT::v4f64, V2, V1,<br>
-                       DAG.getConstant(SHUFPDMask, DL, MVT::i8));<br>
-  }<br>
+  if (SDValue Op =<br>
+      lowerVectorShuffleWithSHUFPD(DL, MVT::v4f64, Mask, V1, V2, DAG))<br>
+    return Op;<br>
<br>
   // Try to simplify this by merging 128-bit lanes to enable a lane-based<br>
   // shuffle. However, if we have AVX2 and either inputs are already in place,<br>
@@ -10156,22 +10172,8 @@ static SDValue lowerV8X64VectorShuffle(S<br>
   if (SDValue Op = lowerVectorShuffleWithVALIGN(DL, VT, Mask, V1, V2, DAG))<br>
     return Op;<br>
<br>
-  // VSHUFPD instruction - mask 0/1, 8/9, 2/3, 10/11, 4/5, 12/13, 6/7, 14/15<br>
-  bool ShufpdMask = true;<br>
-  unsigned Immediate = 0;<br>
-  for (int i = 0; i < 8; ++i) {<br>
-    if (Mask[i] < 0)<br>
-      continue;<br>
-    int Val = (i & 6) + 8 * (i & 1);<br>
-    if (Mask[i] < Val ||  Mask[i] > Val+1) {<br>
-      ShufpdMask = false;<br>
-      break;<br>
-    }<br>
-    Immediate |= (Mask[i]%2) << i;<br>
-  }<br>
-  if (ShufpdMask)<br>
-    return DAG.getNode(X86ISD::SHUFP, DL, VT, V1, V2,<br>
-                       DAG.getConstant(Immediate, DL, MVT::i8));<br>
+  if (SDValue Op = lowerVectorShuffleWithSHUFPD(DL, VT, Mask, V1, V2, DAG))<br>
+    return Op;<br>
<br>
   // PERMILPD instruction - mask 0/1, 0/1, 2/3, 2/3, 4/5, 4/5, 6/7, 6/7<br>
   if (isSingleInputShuffleMask(Mask)) {<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/avx512-shuffle.ll<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_CodeGen_X86_avx512-2Dshuffle.ll-3Frev-3D238918-26r1-3D238917-26r2-3D238918-26view-3Ddiff&d=AwMGaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=BTXejm0exaZrtAaWIMwO24qGYjKnMgiCqIPbXPCSIOI&s=LEpQ8lSlAvHhxbMhKnxLv4XuN5wUx_y_LmX_jQZvfIs&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/avx512-shuffle.ll?rev=238918&r1=238917&r2=238918&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/avx512-shuffle.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/avx512-shuffle.ll Wed Jun  3 06:21:01 2015<br>
@@ -242,3 +242,11 @@ define <16 x i32> @test31(<16 x i32> %a,<br>
   %c = shufflevector <16 x i32> %a, <16 x i32> %b, <16 x i32> <i32 3, i32 4, i32 5, i32 undef, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 16, i32 17, i32 18><br>
   ret <16 x i32> %c<br>
 }<br>
+<br>
+; CHECK-LABEL: test32<br>
+; CHECK: vshufpd $99, %zmm0, %zmm1<br>
+; CHECK: ret<br>
+define <8 x double> @test32(<8 x double> %a, <8 x double> %b) nounwind {<br>
+  %c = shufflevector <8 x double> %a, <8 x double> %b, <8 x i32> <i32 9, i32 1, i32 10, i32 2, i32 undef, i32 5, i32 15, i32 undef><br>
+  ret <8 x double> %c<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>

<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>