[llvm-bugs] [Bug 50104] New: Missing pattern (32 - popcount(a)) - > (popcount(~a))

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 23 10:52:05 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50104

            Bug ID: 50104
           Summary: Missing pattern (32 - popcount(a)) - > (popcount(~a))
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

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!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210423/2a45cf5a/attachment.html>


More information about the llvm-bugs mailing list