<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] keep math/logic on vector unit to avoid insert/extract"
   href="https://bugs.llvm.org/show_bug.cgi?id=40135">40135</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86] keep math/logic on vector unit to avoid insert/extract
          </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>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We have a potential regression with shift lowering via rotates while trying to
do scalarization in:
<a href="https://reviews.llvm.org/D55722">https://reviews.llvm.org/D55722</a>

I don't think we're allowed to do anything with this in IR even if the pattern
was appearing there:

define <4 x i32> @shiftamount_math(<4 x i32> %x, <4 x i32> %y) {
  %e = extractelement <4 x i32> %x, i32 0
  %s = sub i32 32, %e
  %i = insertelement <4 x i32> undef, i32 %s, i32 0
  %splat = shufflevector <4 x i32> %i, <4 x i32> undef, <4 x i32>
zeroinitializer
  %shift = shl <4 x i32> %y, %splat
  ret <4 x i32> %shift
}

$ llc -o - vecshift.ll
...
        movd    %xmm0, %eax
        movl    $32, %ecx
        subl    %eax, %ecx
        movd    %ecx, %xmm0
        pslld   %xmm0, %xmm1
        movdqa  %xmm1, %xmm0
        retq


We would probably be better off loading the '32' as a splat constant and doing
the 'sub' as a vector op:
        movdqa  LCPI1_0(%rip), %xmm2    ## xmm2 = [32,32,32,32]
        psubd   %xmm0, %xmm2
        pxor    %xmm0, %xmm0
        movss   %xmm2, %xmm0            ## xmm0 = xmm2[0],xmm0[1,2,3]
        pslld   %xmm0, %xmm1
        movdqa  %xmm1, %xmm0

It's ugly because of the x86
vector-shift-by-variable-but-not-really-a-vector-shift instruction that takes a
64-bit shift amount, but that beats transferring to scalar and back?</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>