[llvm-bugs] [Bug 36260] New: Possibly missed optimization (performance and code size) when comparing floats as raw binary

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 6 17:45:57 PST 2018


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

            Bug ID: 36260
           Summary: Possibly missed optimization (performance and code
                    size) when comparing floats as raw binary
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kobalicek.petr at gmail.com
                CC: llvm-bugs at lists.llvm.org

The following code
------------------

#include <stdint.h>
#include <xmmintrin.h>
#include <emmintrin.h>

union F64 {
  double d;
  uint64_t u;
};

uint32_t compareBin(double a, double b) noexcept {
  F64 a_ = { a };
  F64 b_ = { b };
  return a_.u == b_.u;
}

uint32_t compareDbl(double a, double b) noexcept {
  return a == b;
}


Compiles to (-O2 -mavx2 -fno-math-errno):
-----------------------------------------

compareBin(double, double): # @compareBin(double, double)
  vmovq rcx, xmm0
  vmovq rdx, xmm1
  xor eax, eax
  cmp rcx, rdx
  sete al
  ret

compareDbl(double, double): # @compareDbl(double, double)
  vcmpeqsd xmm0, xmm0, xmm1
  vmovq rax, xmm0
  and eax, 1
  ret


I think the `compareBin` should use the same approach as `compareDbl`, which
would be:

compareBin(double, double):
  vpcmpeqq xmm0, xmm0, xmm1
  vmovq rax, xmm0
  and eax, 1
  ret

-- 
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/20180207/09bf2eee/attachment.html>


More information about the llvm-bugs mailing list