<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 - Missing trunc(ctpop(zext(x))) -> ctpop(x) fold"
   href="https://bugs.llvm.org/show_bug.cgi?id=50141">50141</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing trunc(ctpop(zext(x))) -> ctpop(x) fold
          </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>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>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>david.bolvansky@gmail.com, lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, nikita.ppv@gmail.com, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://simd.godbolt.org/z/EcP4en5KG">https://simd.godbolt.org/z/EcP4en5KG</a>

#include <x86intrin.h>

__v8hu ctpop_int(__v8hu x) {
    return (__v8hu) {
        (unsigned short)__builtin_popcount( x[0] ),
        (unsigned short)__builtin_popcount( x[1] ),
        (unsigned short)__builtin_popcount( x[2] ),
        (unsigned short)__builtin_popcount( x[3] ),
        (unsigned short)__builtin_popcount( x[4] ),
        (unsigned short)__builtin_popcount( x[5] ),
        (unsigned short)__builtin_popcount( x[6] ),
        (unsigned short)__builtin_popcount( x[7] )
    };
}

define <8 x i16> @ctpop_int(<8 x i16> %0){
  %2 = zext <8 x i16> %0 to <8 x i32>
  %3 = call <8 x i32> @llvm.ctpop.v8i32(<8 x i32> %2)
  %4 = trunc <8 x i32> %3 to <8 x i16>
  ret <8 x i16> %4
}
declare <8 x i32> @llvm.ctpop.v8i32(<8 x i32>)

We should be able to just use a @llvm.ctpop.v8i16 call

Not sure if the trunc is vital, or whether we should also allow the fold:

    ctpop(zext(x)) -> zext(ctpop(x))</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>