<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - Failing to vector constant fold vXi64 on 32-bit targets"
   href="https://llvm.org/bugs/show_bug.cgi?id=30760">30760</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Failing to vector constant fold vXi64 on 32-bit targets
          </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>Windows NT
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </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>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>We are failing to constant fold when have the opportunity because we are
perhaps too strict with only folding to legal scalar types.

e.g.

define <2 x i64> @foldv2i64() nounwind {
  %out = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> <i64 256, i64 -1>, i1 0)
  ret <2 x i64> %out
}

This works fine for 64-bit targets:

llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1

foldv2i64:
# BB#0:
  movl $8, %eax
  movd %rax, %xmm0
  retq

But for 32-bit targets we fail to fold as although v2i64 is legal, i64 isn't:

llc < %s -mtriple=i686-unknown-unknown -mattr=+sse4.1 

foldv2i64:
# BB#0:
  movdqa {{.*#+}} xmm0 = [256,0,4294967295,4294967295]
  pxor %xmm1, %xmm1
  pxor %xmm2, %xmm2
  psubq %xmm0, %xmm2
  pand %xmm0, %xmm2
  psubq {{\.LCPI.*}}, %xmm2
  movdqa {{.*#+}} xmm3 = [15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15]
  movdqa %xmm2, %xmm4
  pand %xmm3, %xmm4
  movdqa {{.*#+}} xmm0 = [0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4]
  movdqa %xmm0, %xmm5
  pshufb %xmm4, %xmm5
  psrlw $4, %xmm2
  pand %xmm3, %xmm2
  pshufb %xmm2, %xmm0
  paddb %xmm5, %xmm0
  psadbw %xmm1, %xmm0
  retl</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>