<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 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Menlo;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        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.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></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">Hopefully fixed with r312253. My attempt at preventing element splits wasn’t’ strong enough.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> fglaser@apple.com [mailto:fglaser@apple.com]
<b>On Behalf Of </b>escha@apple.com<br>
<b>Sent:</b> Thursday, August 31, 2017 1:41 AM<br>
<b>To:</b> Topper, Craig <craig.topper@intel.com><br>
<b>Cc:</b> llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r311892 - [DAGCombiner] Teach visitEXTRACT_SUBVECTOR to turn extracts of BUILD_VECTOR into smaller BUILD_VECTORs<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here’s what it looks like.<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I added debug statements as follows:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">  </span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#3E1E81">fprintf</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">(</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#78492A">stderr</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">,</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#D12F1B">"foo\n"</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">);</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#3E1E81"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">  V.<span style="color:#31595D">dump</span>();<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black"> 
</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#008400">// Skip bitcasting<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">  V =
</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#31595D">peekThroughBitcast</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">(V);</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#31595D"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">  V.<span style="color:#31595D">dump</span>();<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black"> 
</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#008400">// If the input is a build vector. Try to make a smaller build vector.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black"> 
</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#BA2DA2">if</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black"> (V-></span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#31595D">getOpcode</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">()
 == </span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#4F8187">ISD</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">::</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#31595D">BUILD_VECTOR</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">)
 {</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#31595D"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">   
<span style="color:#BA2DA2">if</span> (<span style="color:#BA2DA2">auto</span> *Idx = dyn_cast<ConstantSDNode>(N->getOperand(<span style="color:#272AD8">1</span>))) {<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     
<span style="color:#4F8187">EVT</span> InVT = V-><span style="color:#31595D">getValueType</span>(<span style="color:#272AD8">0</span>);<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     
<span style="color:#BA2DA2">unsigned</span> NumElems = NVT.<span style="color:#31595D">getSizeInBits</span>() / InVT.<span style="color:#31595D">getScalarSizeInBits</span>();<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     
<span style="color:#3E1E81">fprintf</span>(<span style="color:#78492A">stderr</span>,<span style="color:#D12F1B">"%d %d %d\n"</span>, NVT.<span style="color:#31595D">getSizeInBits</span>(), InVT.<span style="color:#31595D">getScalarSizeInBits</span>(), NumElems);<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     
<span style="color:#BA2DA2">if</span> (NumElems > <span style="color:#272AD8">0</span>) {<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">       
<span style="color:#4F8187">EVT</span> ExtractVT = <span style="color:#4F8187">EVT</span>::<span style="color:#31595D">getVectorVT</span>(*<span style="color:#4F8187">DAG</span>.<span style="color:#31595D">getContext</span>(),<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                         InVT.<span style="color:#31595D">getVectorElementType</span>(), NumElems);<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">       
<span style="color:#BA2DA2">if</span> (!LegalOperations ||<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         
<span style="color:#BA2DA2">unsigned</span> IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                            InVT.getScalarSizeInBits();<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         
<span style="color:#3E1E81">fprintf</span>(<span style="color:#78492A">stderr</span>,<span style="color:#D12F1B">"%d\n"</span>, IdxVal);<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif;color:black">         
</span><span style="font-size:8.5pt;font-family:"Menlo",serif;color:#008400">// Extract the pieces from the original build_vector.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         
<span style="color:#4F8187">SDValue</span> BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                            makeArrayRef(V->op_begin() + IdxVal,<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                                         NumElems));<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">          BuildVec.<span style="color:#31595D">dump</span>();<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         
<span style="color:#BA2DA2">return</span> <span style="color:#4F8187">DAG</span>.<span style="color:#31595D">getBitcast</span>(NVT, BuildVec);<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">        }<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">      }<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">    }<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">  }<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">This results in the following printout<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">Combining: t12: v3f16 = extract_subvector t168, Constant:i32<0><o:p></o:p></span></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">foo<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">t168: v4f16 = bitcast t167<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">t167: v2f32 = BUILD_VECTOR t164, t166<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">48 32 1<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">0<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">Creating new node: t170: v1f32 = BUILD_VECTOR t164<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">t170: v1f32 = BUILD_VECTOR t164<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">Assertion failed: (VT.getSizeInBits() == Operand.getValueSizeInBits() && "Cannot BITCAST between types of different sizes!"), function getNode, file ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp,
 line 37<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">97.<o:p></o:p></span></p>
</div>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Note how what it’s attempting to do here just… doesn’t seem to make much sense, per the printout.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">—escha<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Aug 30, 2017, at 3:34 PM, Topper, Craig <<a href="mailto:craig.topper@intel.com">craig.topper@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Escha,</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">This should be calculating the type for the BUILD_VECTOR with same scalar size but less elements. It uses NVT to get the result vector width, and InVT to get
 the scalar size of the original BUILD_VECTOR. If InVT’s element size is bigger than NVT it gives up.</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">      unsigned NumElems = NVT.getSizeInBits() / InVT.getScalarSizeInBits();</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">      if (NumElems > 0) {</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">        EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">                                         InVT.getVectorElementType(), NumElems);</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Do you have any additional information?</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
</div>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<div>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span class="apple-converted-space"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><a href="mailto:fglaser@apple.com">fglaser@apple.com</a>
 [<a href="mailto:fglaser@apple.com">mailto:fglaser@apple.com</a>]<span class="apple-converted-space"> </span><b>On Behalf Of<span class="apple-converted-space"> </span></b><a href="mailto:escha@apple.com">escha@apple.com</a><br>
<b>Sent:</b><span class="apple-converted-space"> </span>Wednesday, August 30, 2017 3:05 PM<br>
<b>To:</b><span class="apple-converted-space"> </span>Topper, Craig <<a href="mailto:craig.topper@intel.com">craig.topper@intel.com</a>><br>
<b>Cc:</b><span class="apple-converted-space"> </span><a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<b>Subject:</b><span class="apple-converted-space"> </span>Re: [llvm] r311892 - [DAGCombiner] Teach visitEXTRACT_SUBVECTOR to turn extracts of BUILD_VECTOR into smaller BUILD_VECTORs</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">This breaks a test on our backend, but I suspect the patch is slightly bugged. Note the following:<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">  <span style="color:#008400">// Skip bitcasting</span></span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">  V =<span class="apple-converted-space"> </span><span style="color:#31595D">peekThroughBitcast</span>(V);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif"> <span class="apple-converted-space"> </span><span style="color:#008400">// If the input is a build vector. Try to make a smaller build vector.</span></span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif"> <span class="apple-converted-space"> </span><span style="color:#BA2DA2">if</span><span class="apple-converted-space"> </span>(V-><span style="color:#31595D">getOpcode</span>()
 ==<span class="apple-converted-space"> </span><span style="color:#4F8187">ISD</span>::<span style="color:#31595D">BUILD_VECTOR</span>) {</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">    <span style="color:#BA2DA2">if</span><span class="apple-converted-space"> </span>(<span style="color:#BA2DA2">auto</span><span class="apple-converted-space"> </span>*Idx
 = dyn_cast<ConstantSDNode>(N->getOperand(<span style="color:#272AD8">1</span>))) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     <span class="apple-converted-space"> </span><span style="color:#4F8187">EVT</span><span class="apple-converted-space"> </span>InVT = V-><span style="color:#31595D">getValueType</span>(<span style="color:#272AD8">0</span>);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">      <span style="color:#BA2DA2">unsigned</span><span class="apple-converted-space"> </span>NumElems = NVT.<span style="color:#31595D">getSizeInBits</span>()
 / InVT.<span style="color:#31595D">getScalarSizeInBits</span>();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">     <span class="apple-converted-space"> </span><span style="color:#BA2DA2">if</span><span class="apple-converted-space"> </span>(NumElems ><span class="apple-converted-space"> </span><span style="color:#272AD8">0</span>)
 {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">       <span class="apple-converted-space"> </span><span style="color:#4F8187">EVT</span><span class="apple-converted-space"> </span>ExtractVT =<span class="apple-converted-space"> </span><span style="color:#4F8187">EVT</span>::<span style="color:#31595D">getVectorVT</span>(*<span style="color:#4F8187">DAG</span>.<span style="color:#31595D">getContext</span>(),</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                         InVT.<span style="color:#31595D">getVectorElementType</span>(), NumElems);</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">       <span class="apple-converted-space"> </span><span style="color:#BA2DA2">if</span><span class="apple-converted-space"> </span>(!LegalOperations ||</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         <span class="apple-converted-space"> </span><span style="color:#BA2DA2">unsigned</span><span class="apple-converted-space"> </span>IdxVal = Idx->getZExtValue()
 * NVT.getScalarSizeInBits() /</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                            InVT.getScalarSizeInBits();</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:9.0pt;font-family:"Helvetica",sans-serif"> </span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         <span class="apple-converted-space"> </span><span style="color:#008400">// Extract the pieces from the original build_vector.</span></span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">         <span class="apple-converted-space"> </span><span style="color:#4F8187">SDValue</span><span class="apple-converted-space"> </span>BuildVec = DAG.getBuildVector(ExtractVT,
 SDLoc(N),</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                            makeArrayRef(V->op_begin() + IdxVal,</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="background:white"><span style="font-size:8.5pt;font-family:"Menlo",serif">                                                         NumElems));</span><o:p></o:p></p>
</div>
</div>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">Note how we peak through a bitcast, but then use the original type for much of these calculations. So if the element size changed, we break (in this case, a bitcast from v2f32 to v4f16).<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">—escha<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">On Aug 28, 2017, at 8:28 AM, Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org"><span style="color:purple">llvm-commits@lists.llvm.org</span></a>> wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">Author: ctopper<br>
Date: Mon Aug 28 08:28:33 2017<br>
New Revision: 311892<br>
<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=311892&view=rev"><span style="color:purple">http://llvm.org/viewvc/llvm-project?rev=311892&view=rev</span></a><br>
Log:<br>
[DAGCombiner] Teach visitEXTRACT_SUBVECTOR to turn extracts of BUILD_VECTOR into smaller BUILD_VECTORs<br>
<br>
Only do this before operations are legalized of BUILD_VECTOR is Legal for the target.<br>
<br>
Differential Revision:<span class="apple-converted-space"> </span><a href="https://reviews.llvm.org/D37186"><span style="color:purple">https://reviews.llvm.org/D37186</span></a><br>
<br>
Modified:<br>
   llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
   llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll<br>
   llvm/trunk/test/CodeGen/X86/widen_extract-1.ll<br>
<br>
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=311892&r1=311891&r2=311892&view=diff"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=311892&r1=311891&r2=311892&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Aug 28 08:28:33 2017<br>
@@ -15157,6 +15157,29 @@ SDValue DAGCombiner::visitEXTRACT_SUBVEC<br>
  // Skip bitcasting<br>
  V = peekThroughBitcast(V);<br>
<br>
+  // If the input is a build vector. Try to make a smaller build vector.<br>
+  if (V->getOpcode() == ISD::BUILD_VECTOR) {<br>
+    if (auto *Idx = dyn_cast<ConstantSDNode>(N->getOperand(1))) {<br>
+      EVT InVT = V->getValueType(0);<br>
+      unsigned NumElems = NVT.getSizeInBits() / InVT.getScalarSizeInBits();<br>
+      if (NumElems > 0) {<br>
+        EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),<br>
+                                         InVT.getVectorElementType(), NumElems);<br>
+        if (!LegalOperations ||<br>
+            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {<br>
+          unsigned IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /<br>
+                            InVT.getScalarSizeInBits();<br>
+<br>
+          // Extract the pieces from the original build_vector.<br>
+          SDValue BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),<br>
+                                            makeArrayRef(V->op_begin() + IdxVal,<br>
+                                                         NumElems));<br>
+          return DAG.getBitcast(NVT, BuildVec);<br>
+        }<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
  if (V->getOpcode() == ISD::INSERT_SUBVECTOR) {<br>
    // Handle only simple case where vector being inserted and vector<br>
    // being extracted are of same size.<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll?rev=311892&r1=311891&r2=311892&view=diff"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll?rev=311892&r1=311891&r2=311892&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll Mon Aug 28 08:28:33 2017<br>
@@ -83,8 +83,7 @@ define <4 x i32> @test_sext_4i8_4i32_und<br>
define <4 x i64> @test_sext_4i8_4i64() {<br>
; X32-LABEL: test_sext_4i8_4i64:<br>
; X32:       # BB#0:<br>
-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = [0,0,4294967295,4294967295]<br>
-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br>
+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = [0,0,4294967295,4294967295,2,0,4294967293,4294967295]<br>
; X32-NEXT:    retl<br>
;<br>
; X64-LABEL: test_sext_4i8_4i64:<br>
@@ -102,8 +101,7 @@ define <4 x i64> @test_sext_4i8_4i64() {<br>
define <4 x i64> @test_sext_4i8_4i64_undef() {<br>
; X32-LABEL: test_sext_4i8_4i64_undef:<br>
; X32:       # BB#0:<br>
-; X32-NEXT:    vpcmpeqd %xmm0, %xmm0, %xmm0<br>
-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br>
+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = <u,u,4294967295,4294967295,u,u,4294967293,4294967295><br>
; X32-NEXT:    retl<br>
;<br>
; X64-LABEL: test_sext_4i8_4i64_undef:<br>
@@ -245,8 +243,7 @@ define <4 x i32> @test_zext_4i8_4i32() {<br>
define <4 x i64> @test_zext_4i8_4i64() {<br>
; X32-LABEL: test_zext_4i8_4i64:<br>
; X32:       # BB#0:<br>
-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = [0,0,255,0]<br>
-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br>
+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = [0,0,255,0,2,0,253,0]<br>
; X32-NEXT:    retl<br>
;<br>
; X64-LABEL: test_zext_4i8_4i64:<br>
@@ -300,10 +297,7 @@ define <4 x i32> @test_zext_4i8_4i32_und<br>
define <4 x i64> @test_zext_4i8_4i64_undef() {<br>
; X32-LABEL: test_zext_4i8_4i64_undef:<br>
; X32:       # BB#0:<br>
-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = <u,u,255,0><br>
-; X32-NEXT:    movl $2, %eax<br>
-; X32-NEXT:    vmovd %eax, %xmm1<br>
-; X32-NEXT:    vinsertf128 $1, %xmm1, %ymm0, %ymm0<br>
+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = <u,u,255,0,2,0,u,u><br>
; X32-NEXT:    retl<br>
;<br>
; X64-LABEL: test_zext_4i8_4i64_undef:<br>
<br>
Modified: llvm/trunk/test/CodeGen/X86/widen_extract-1.ll<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/widen_extract-1.ll?rev=311892&r1=311891&r2=311892&view=diff"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/widen_extract-1.ll?rev=311892&r1=311891&r2=311892&view=diff</span></a><br>
==============================================================================<br>
--- llvm/trunk/test/CodeGen/X86/widen_extract-1.ll (original)<br>
+++ llvm/trunk/test/CodeGen/X86/widen_extract-1.ll Mon Aug 28 08:28:33 2017<br>
@@ -7,8 +7,8 @@<br>
define void @convert(<2 x double>* %dst.addr, <3 x double> %src)  {<br>
; X32-LABEL: convert:<br>
; X32:       # BB#0: # %entry<br>
-; X32-NEXT:    movups {{[0-9]+}}(%esp), %xmm0<br>
; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax<br>
+; X32-NEXT:    movups {{[0-9]+}}(%esp), %xmm0<br>
; X32-NEXT:    movaps %xmm0, (%eax)<br>
; X32-NEXT:    retl<br>
;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org"><span style="color:purple">llvm-commits@lists.llvm.org</span></a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits"><span style="color:purple">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</span></a><o:p></o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>