<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 - [InstCombine] hoist vector cast above splat as scalar cast?"
   href="https://bugs.llvm.org/show_bug.cgi?id=32865">32865</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] hoist vector cast above splat as scalar cast?
          </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>Scalar Optimizations
          </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>Forking this off from <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Poor AVX code generation on 8xi1 masks"
   href="show_bug.cgi?id=14657">bug 14657</a>.

One of these should be canonical:

define <8 x i32> @sext_last(i16 %x) {
  %ins = insertelement <8 x i16> undef, i16 %x, i32 0
  %splat = shufflevector <8 x i16> %ins, <8 x i16> undef, <8 x i32>
zeroinitializer
  %sext = sext <8 x i16> %splat to <8 x i32>
  ret <8 x i32> %sext
}

define <8 x i32> @sext_first(i16 %x) {
  %sext = sext i16 %x to i32
  %ins = insertelement <8 x i32> undef, i32 %sext, i32 0
  %splat = shufflevector <8 x i32> %ins, <8 x i32> undef, <8 x i32>
zeroinitializer
  ret <8 x i32> %splat
}

We may need to prepare the backend to expect the canonical pattern to avoid
regressions. Eg, with AVX1, there's a big difference in codegen:

$ ./llc -o - splatsext.ll -mattr=avx
_sext_last:                             ## @sext_last
        vmovd   %edi, %xmm0
        vpshuflw        $0, %xmm0, %xmm0 ## xmm0 = xmm0[0,0,0,0,4,5,6,7]
        vpshufd $80, %xmm0, %xmm0       ## xmm0 = xmm0[0,0,1,1]
        vpmovsxwd       %xmm0, %xmm1
        vpshufd $78, %xmm0, %xmm0       ## xmm0 = xmm0[2,3,0,1]
        vpmovsxwd       %xmm0, %xmm0
        vinsertf128     $1, %xmm0, %ymm1, %ymm0

_sext_first:                            ## @sext_first
        movswl  %di, %eax
        vmovd   %eax, %xmm0
        vpshufd $0, %xmm0, %xmm0        ## xmm0 = xmm0[0,0,0,0]
        vinsertf128     $1, %xmm0, %ymm0, %ymm0</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>