<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [x86, SSE] poor codegen splatting from illegal truncated vector type"
   href="https://bugs.llvm.org/show_bug.cgi?id=32160">32160</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86, SSE] poor codegen splatting from illegal truncated vector type
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: X86
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This is fallout noted by Eli from the proposed InstCombine in: 
<a href="https://reviews.llvm.org/D30123">https://reviews.llvm.org/D30123</a> 

define <8 x i16> @narrow_splat1(<8 x i32> %x) {
  %shuf = trunc <8 x i32> %x to <8 x i16>
  %trunc = shufflevector <8 x i16> %shuf, <8 x i16> undef, <8 x i32> <i32 2,
i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2>
  ret <8 x i16> %trunc
}

$ ./llc -o - widesplat.ll 
        pslld   $16, %xmm1
        psrad   $16, %xmm1
        pslld   $16, %xmm0
        psrad   $16, %xmm0
        packssdw        %xmm1, %xmm0
        pshuflw $170, %xmm0, %xmm0      ## xmm0 = xmm0[2,2,2,2,4,5,6,7]
        pshufd  $80, %xmm0, %xmm0       ## xmm0 = xmm0[0,0,1,1]
        retq


Something (demandedbits?) should tell us that %xmm1 isn't necessary here.

This could have been (if the shuffle was before the trunc):
        pshufd  $170, %xmm0, %xmm0      ## xmm0 = xmm0[2,2,2,2]
        pslld   $16, %xmm0
        psrad   $16, %xmm0
        packssdw        %xmm0, %xmm0
        retq

Or some combination of pslldq + pshuflw + pshufhw?


The DAG looks like this before any x86 shuffling kicks in:
          t2: v4i32,ch = CopyFromReg t0, Register:v4i32 %vreg0
          t4: v4i32,ch = CopyFromReg t0, Register:v4i32 %vreg1
        t5: v8i32 = concat_vectors t2, t4
      t6: v8i16 = truncate t5
    t8: v8i16 = vector_shuffle<2,2,2,2,2,2,2,2> t6, undef:v8i16</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>