<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Here’s what it looks like.<div class=""><br class=""></div><div class="">I added debug statements as follows:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">  </span>fprintf<span style="color: #000000" class="">(</span><span style="color: #78492a" class="">stderr</span><span style="color: #000000" class="">,</span><span style="color: #d12f1b" class="">"foo\n"</span><span style="color: #000000" class="">);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">  V.<span style="color: #31595d" class="">dump</span>();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">  </span>// Skip bitcasting</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">  V = </span>peekThroughBitcast<span style="color: #000000" class="">(V);</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">  V.<span style="color: #31595d" class="">dump</span>();</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">  </span>// If the input is a build vector. Try to make a smaller build vector.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">  </span><span style="color: #ba2da2" class="">if</span><span style="color: #000000" class=""> (V-></span>getOpcode<span style="color: #000000" class="">() == </span><span style="color: #4f8187" class="">ISD</span><span style="color: #000000" class="">::</span>BUILD_VECTOR<span style="color: #000000" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">    <span style="color: #ba2da2" class="">if</span> (<span style="color: #ba2da2" class="">auto</span> *Idx = dyn_cast<ConstantSDNode>(N->getOperand(<span style="color: #272ad8" class="">1</span>))) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">      <span style="color: #4f8187" class="">EVT</span> InVT = V-><span style="color: #31595d" class="">getValueType</span>(<span style="color: #272ad8" class="">0</span>);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">      <span style="color: #ba2da2" class="">unsigned</span> NumElems = NVT.<span style="color: #31595d" class="">getSizeInBits</span>() / InVT.<span style="color: #31595d" class="">getScalarSizeInBits</span>();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">      <span style="color: #3e1e81" class="">fprintf</span>(<span style="color: #78492a" class="">stderr</span>,<span style="color: #d12f1b" class="">"%d %d %d\n"</span>, NVT.<span style="color: #31595d" class="">getSizeInBits</span>(), InVT.<span style="color: #31595d" class="">getScalarSizeInBits</span>(), NumElems);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">      <span style="color: #ba2da2" class="">if</span> (NumElems > <span style="color: #272ad8" class="">0</span>) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">        <span style="color: #4f8187" class="">EVT</span> ExtractVT = <span style="color: #4f8187" class="">EVT</span>::<span style="color: #31595d" class="">getVectorVT</span>(*<span style="color: #4f8187" class="">DAG</span>.<span style="color: #31595d" class="">getContext</span>(),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">                                         InVT.<span style="color: #31595d" class="">getVectorElementType</span>(), NumElems);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">        <span style="color: #ba2da2" class="">if</span> (!LegalOperations ||</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">          <span style="color: #ba2da2" class="">unsigned</span> IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">                            InVT.getScalarSizeInBits();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">          <span style="color: #3e1e81" class="">fprintf</span>(<span style="color: #78492a" class="">stderr</span>,<span style="color: #d12f1b" class="">"%d\n"</span>, IdxVal);</div><div style="margin: 0px; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="color: #000000" class="">          </span>// Extract the pieces from the original build_vector.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">          <span style="color: #4f8187" class="">SDValue</span> BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">                                            makeArrayRef(V->op_begin() + IdxVal,</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">                                                         NumElems));</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">          BuildVec.<span style="color: #31595d" class="">dump</span>();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">          <span style="color: #ba2da2" class="">return</span> <span style="color: #4f8187" class="">DAG</span>.<span style="color: #31595d" class="">getBitcast</span>(NVT, BuildVec);</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">        }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">      }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">    }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">  }</div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">This results in the following printout</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Combining: t12: v3f16 = extract_subvector t168, Constant:i32<0></span></div></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">foo</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">t168: v4f16 = bitcast t167</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">t167: v2f32 = BUILD_VECTOR t164, t166</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">48 32 1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">0</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Creating new node: t170: v1f32 = BUILD_VECTOR t164</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">t170: v1f32 = BUILD_VECTOR t164</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Assertion failed: (VT.getSizeInBits() == Operand.getValueSizeInBits() && "Cannot BITCAST between types of different sizes!"), function getNode, file ../lib/CodeGen/SelectionDAG/SelectionDAG.cpp, line 37</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">97.</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Note how what it’s attempting to do here just… doesn’t seem to make much sense, per the printout.</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class="">—escha</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Aug 30, 2017, at 3:34 PM, Topper, Craig <<a href="mailto:craig.topper@intel.com" class="">craig.topper@intel.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Hi Escha,<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">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.<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(31, 73, 125);" class="">      unsigned NumElems = NVT.getSizeInBits() / InVT.getScalarSizeInBits();<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(31, 73, 125);" class="">      if (NumElems > 0) {<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(31, 73, 125);" class="">        EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(31, 73, 125);" class="">                                         InVT.getVectorElementType(), NumElems);<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: 'Courier New'; color: rgb(31, 73, 125);" class=""><o:p class=""> </o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Do you have any additional information?<o:p class=""></o:p></span></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><a name="_MailEndCompose" class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><o:p class=""> </o:p></span></a></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><a name="_____replyseparator" class=""></a><b class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">From:</span></b><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span><a href="mailto:fglaser@apple.com" class="">fglaser@apple.com</a> [<a href="mailto:fglaser@apple.com" class="">mailto:fglaser@apple.com</a>]<span class="Apple-converted-space"> </span><b class="">On Behalf Of<span class="Apple-converted-space"> </span></b><a href="mailto:escha@apple.com" class="">escha@apple.com</a><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Wednesday, August 30, 2017 3:05 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Topper, Craig <craig.topper@intel.com><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>llvm-commits@lists.llvm.org<br class=""><b class="">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<o:p class=""></o:p></span></div></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">This breaks a test on our backend, but I suspect the patch is slightly bugged. Note the following:<o:p class=""></o:p></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">  </span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(0, 132, 0);" class="">// Skip bitcasting<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">  V =<span class="Apple-converted-space"> </span></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(49, 89, 93);" class="">peekThroughBitcast</span><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">(V);</span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(49, 89, 93);" class=""><o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class=""> <span class="Apple-converted-space"> </span></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(0, 132, 0);" class="">// If the input is a build vector. Try to make a smaller build vector.<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class=""> <span class="Apple-converted-space"> </span></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(186, 45, 162);" class="">if</span><span style="font-size: 8.5pt; font-family: Menlo, serif;" class=""><span class="Apple-converted-space"> </span>(V-></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(49, 89, 93);" class="">getOpcode</span><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">() ==<span class="Apple-converted-space"> </span></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(79, 129, 135);" class="">ISD</span><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">::</span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(49, 89, 93);" class="">BUILD_VECTOR</span><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">) {</span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(49, 89, 93);" class=""><o:p class=""></o:p></span></div></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">    <span style="color: rgb(186, 45, 162);" class="">if</span><span class="Apple-converted-space"> </span>(<span style="color: rgb(186, 45, 162);" class="">auto</span><span class="Apple-converted-space"> </span>*Idx = dyn_cast<ConstantSDNode>(N->getOperand(<span style="color: rgb(39, 42, 216);" class="">1</span>))) {<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">     <span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">EVT</span><span class="Apple-converted-space"> </span>InVT = V-><span style="color: rgb(49, 89, 93);" class="">getValueType</span>(<span style="color: rgb(39, 42, 216);" class="">0</span>);<o:p class=""></o:p></span></div></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">      <span style="color: rgb(186, 45, 162);" class="">unsigned</span><span class="Apple-converted-space"> </span>NumElems = NVT.<span style="color: rgb(49, 89, 93);" class="">getSizeInBits</span>() / InVT.<span style="color: rgb(49, 89, 93);" class="">getScalarSizeInBits</span>();<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">     <span class="Apple-converted-space"> </span><span style="color: rgb(186, 45, 162);" class="">if</span><span class="Apple-converted-space"> </span>(NumElems ><span class="Apple-converted-space"> </span><span style="color: rgb(39, 42, 216);" class="">0</span>) {<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">       <span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">EVT</span><span class="Apple-converted-space"> </span>ExtractVT =<span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">EVT</span>::<span style="color: rgb(49, 89, 93);" class="">getVectorVT</span>(*<span style="color: rgb(79, 129, 135);" class="">DAG</span>.<span style="color: rgb(49, 89, 93);" class="">getContext</span>(),<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">                                         InVT.<span style="color: rgb(49, 89, 93);" class="">getVectorElementType</span>(), NumElems);<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">       <span class="Apple-converted-space"> </span><span style="color: rgb(186, 45, 162);" class="">if</span><span class="Apple-converted-space"> </span>(!LegalOperations ||<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">         <span class="Apple-converted-space"> </span><span style="color: rgb(186, 45, 162);" class="">unsigned</span><span class="Apple-converted-space"> </span>IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">                            InVT.getScalarSizeInBits();<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 9pt; font-family: Helvetica, sans-serif;" class=""><o:p class=""> </o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">         <span class="Apple-converted-space"> </span></span><span style="font-size: 8.5pt; font-family: Menlo, serif; color: rgb(0, 132, 0);" class="">// Extract the pieces from the original build_vector.<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">         <span class="Apple-converted-space"> </span><span style="color: rgb(79, 129, 135);" class="">SDValue</span><span class="Apple-converted-space"> </span>BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">                                            makeArrayRef(V->op_begin() + IdxVal,<o:p class=""></o:p></span></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif; background-color: white;" class=""><span style="font-size: 8.5pt; font-family: Menlo, serif;" class="">                                                         NumElems));<o:p class=""></o:p></span></div></div></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">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 class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">—escha<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div class=""><blockquote style="margin-top: 5pt; margin-bottom: 5pt;" class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">On Aug 28, 2017, at 8:28 AM, Craig Topper via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" style="color: purple; text-decoration: underline;" class="">llvm-commits@lists.llvm.org</a>> wrote:<o:p class=""></o:p></div></div><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">Author: ctopper<br class="">Date: Mon Aug 28 08:28:33 2017<br class="">New Revision: 311892<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=311892&view=rev" style="color: purple; text-decoration: underline;" class="">http://llvm.org/viewvc/llvm-project?rev=311892&view=rev</a><br class="">Log:<br class="">[DAGCombiner] Teach visitEXTRACT_SUBVECTOR to turn extracts of BUILD_VECTOR into smaller BUILD_VECTORs<br class=""><br class="">Only do this before operations are legalized of BUILD_VECTOR is Legal for the target.<br class=""><br class="">Differential Revision:<span class="Apple-converted-space"> </span><a href="https://reviews.llvm.org/D37186" style="color: purple; text-decoration: underline;" class="">https://reviews.llvm.org/D37186</a><br class=""><br class="">Modified:<br class="">   llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br class="">   llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll<br class="">   llvm/trunk/test/CodeGen/X86/widen_extract-1.ll<br class=""><br class="">Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br class="">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" style="color: purple; text-decoration: underline;" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=311892&r1=311891&r2=311892&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)<br class="">+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Mon Aug 28 08:28:33 2017<br class="">@@ -15157,6 +15157,29 @@ SDValue DAGCombiner::visitEXTRACT_SUBVEC<br class="">  // Skip bitcasting<br class="">  V = peekThroughBitcast(V);<br class=""><br class="">+  // If the input is a build vector. Try to make a smaller build vector.<br class="">+  if (V->getOpcode() == ISD::BUILD_VECTOR) {<br class="">+    if (auto *Idx = dyn_cast<ConstantSDNode>(N->getOperand(1))) {<br class="">+      EVT InVT = V->getValueType(0);<br class="">+      unsigned NumElems = NVT.getSizeInBits() / InVT.getScalarSizeInBits();<br class="">+      if (NumElems > 0) {<br class="">+        EVT ExtractVT = EVT::getVectorVT(*DAG.getContext(),<br class="">+                                         InVT.getVectorElementType(), NumElems);<br class="">+        if (!LegalOperations ||<br class="">+            TLI.isOperationLegal(ISD::BUILD_VECTOR, ExtractVT)) {<br class="">+          unsigned IdxVal = Idx->getZExtValue() * NVT.getScalarSizeInBits() /<br class="">+                            InVT.getScalarSizeInBits();<br class="">+<br class="">+          // Extract the pieces from the original build_vector.<br class="">+          SDValue BuildVec = DAG.getBuildVector(ExtractVT, SDLoc(N),<br class="">+                                            makeArrayRef(V->op_begin() + IdxVal,<br class="">+                                                         NumElems));<br class="">+          return DAG.getBitcast(NVT, BuildVec);<br class="">+        }<br class="">+      }<br class="">+    }<br class="">+  }<br class="">+<br class="">  if (V->getOpcode() == ISD::INSERT_SUBVECTOR) {<br class="">    // Handle only simple case where vector being inserted and vector<br class="">    // being extracted are of same size.<br class=""><br class="">Modified: llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll<br class="">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" style="color: purple; text-decoration: underline;" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll?rev=311892&r1=311891&r2=311892&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll (original)<br class="">+++ llvm/trunk/test/CodeGen/X86/fold-vector-sext-zext.ll Mon Aug 28 08:28:33 2017<br class="">@@ -83,8 +83,7 @@ define <4 x i32> @test_sext_4i8_4i32_und<br class="">define <4 x i64> @test_sext_4i8_4i64() {<br class="">; X32-LABEL: test_sext_4i8_4i64:<br class="">; X32:       # BB#0:<br class="">-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = [0,0,4294967295,4294967295]<br class="">-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br class="">+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = [0,0,4294967295,4294967295,2,0,4294967293,4294967295]<br class="">; X32-NEXT:    retl<br class="">;<br class="">; X64-LABEL: test_sext_4i8_4i64:<br class="">@@ -102,8 +101,7 @@ define <4 x i64> @test_sext_4i8_4i64() {<br class="">define <4 x i64> @test_sext_4i8_4i64_undef() {<br class="">; X32-LABEL: test_sext_4i8_4i64_undef:<br class="">; X32:       # BB#0:<br class="">-; X32-NEXT:    vpcmpeqd %xmm0, %xmm0, %xmm0<br class="">-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br class="">+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = <u,u,4294967295,4294967295,u,u,4294967293,4294967295><br class="">; X32-NEXT:    retl<br class="">;<br class="">; X64-LABEL: test_sext_4i8_4i64_undef:<br class="">@@ -245,8 +243,7 @@ define <4 x i32> @test_zext_4i8_4i32() {<br class="">define <4 x i64> @test_zext_4i8_4i64() {<br class="">; X32-LABEL: test_zext_4i8_4i64:<br class="">; X32:       # BB#0:<br class="">-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = [0,0,255,0]<br class="">-; X32-NEXT:    vinsertf128 $1, {{\.LCPI.*}}, %ymm0, %ymm0<br class="">+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = [0,0,255,0,2,0,253,0]<br class="">; X32-NEXT:    retl<br class="">;<br class="">; X64-LABEL: test_zext_4i8_4i64:<br class="">@@ -300,10 +297,7 @@ define <4 x i32> @test_zext_4i8_4i32_und<br class="">define <4 x i64> @test_zext_4i8_4i64_undef() {<br class="">; X32-LABEL: test_zext_4i8_4i64_undef:<br class="">; X32:       # BB#0:<br class="">-; X32-NEXT:    vmovaps {{.*#+}} xmm0 = <u,u,255,0><br class="">-; X32-NEXT:    movl $2, %eax<br class="">-; X32-NEXT:    vmovd %eax, %xmm1<br class="">-; X32-NEXT:    vinsertf128 $1, %xmm1, %ymm0, %ymm0<br class="">+; X32-NEXT:    vmovaps {{.*#+}} ymm0 = <u,u,255,0,2,0,u,u><br class="">; X32-NEXT:    retl<br class="">;<br class="">; X64-LABEL: test_zext_4i8_4i64_undef:<br class=""><br class="">Modified: llvm/trunk/test/CodeGen/X86/widen_extract-1.ll<br class="">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" style="color: purple; text-decoration: underline;" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/widen_extract-1.ll?rev=311892&r1=311891&r2=311892&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/CodeGen/X86/widen_extract-1.ll (original)<br class="">+++ llvm/trunk/test/CodeGen/X86/widen_extract-1.ll Mon Aug 28 08:28:33 2017<br class="">@@ -7,8 +7,8 @@<br class="">define void @convert(<2 x double>* %dst.addr, <3 x double> %src)  {<br class="">; X32-LABEL: convert:<br class="">; X32:       # BB#0: # %entry<br class="">-; X32-NEXT:    movups {{[0-9]+}}(%esp), %xmm0<br class="">; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax<br class="">+; X32-NEXT:    movups {{[0-9]+}}(%esp), %xmm0<br class="">; X32-NEXT:    movaps %xmm0, (%eax)<br class="">; X32-NEXT:    retl<br class="">;<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" style="color: purple; text-decoration: underline;" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" style="color: purple; text-decoration: underline;" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a></div></div></div></blockquote></div></div></div></div></blockquote></div><br class=""></div></body></html>