<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 pattern (32 - popcount(a)) - > (popcount(~a))"
   href="https://bugs.llvm.org/show_bug.cgi?id=50104">50104</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing pattern (32 - popcount(a)) - > (popcount(~a))
          </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>Linux
          </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>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Found in PR50096.

int A(unsigned int a)
{
    return (32 -__builtin_popcount(a));
}




int B(unsigned int a)
{
    return (__builtin_popcount(~a)) ;
}

A(unsigned int):                                  # @A(unsigned int)
        popcnt  ecx, edi
        mov     eax, 32
        sub     eax, ecx
        ret
B(unsigned int):                                  # @B(unsigned int)
        not     edi
        popcnt  eax, edi
        ret

'not' form is better for analysis than a 'sub' form.


----------------------------------------
define i8 @src(i8 %x) {
%0:
  %p = ctpop i8 %x
  %a = sub i8 8, %p
  ret i8 %a
}
=>
define i8 @tgt(i8 %x) {
%0:
  %n = xor i8 %x, 255
  %p = ctpop i8 %n
  ret i8 %p
}
Transformation seems to be correct!</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>