[llvm-bugs] [Bug 50218] New: Failed to combine popcount(x) + popcount(x >> 32) to popcountl(x)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue May 4 04:56:20 PDT 2021


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

            Bug ID: 50218
           Summary: Failed to combine popcount(x) +  popcount(x >> 32) to
                    popcountl(x)
           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

int test(unsigned long x) {
    return __builtin_popcount(x) +  __builtin_popcount(x >> 32);
}



----------------------------------------
define i32 @src(i64 %0) {
%1:
  %2 = trunc i64 %0 to i32
  %3 = ctpop i32 %2
  %4 = lshr i64 %0, 32
  %5 = trunc i64 %4 to i32
  %6 = ctpop i32 %5
  %7 = add i32 %6, %3
  ret i32 %7
}
=>
define i32 @tgt(i64 %0) {
%1:
  %2 = ctpop i64 %0
  %3 = trunc i64 %2 to i32
  ret i32 %3
}
Transformation seems to be correct!

alive: https://alive2.llvm.org/ce/z/XYSuCb

codegen: https://godbolt.org/z/josqoYEed

-- 
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/20210504/09a33f9a/attachment.html>


More information about the llvm-bugs mailing list