[llvm-bugs] [Bug 27164] New: [x86] suboptimal codegen for isfinite IR

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 31 09:39:17 PDT 2016


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

            Bug ID: 27164
           Summary: [x86] suboptimal codegen for isfinite IR
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

define i1 @is_finite(float %x) {
  %1 = tail call float @llvm.fabs.f32(float %x)
  %2 = fcmp one float %1, 0x7FF0000000000000 ; ordered and not equal
  ret i1 %2
}
declare float @llvm.fabs.f32(float)

$ ./llc -o - isfinite.ll

LCPI0_0:
    .long    2147483647              ## 0x7fffffff
    .long    2147483647              ## 0x7fffffff
    .long    2147483647              ## 0x7fffffff
    .long    2147483647              ## 0x7fffffff
    .section    __TEXT,__literal4,4byte_literals
    .p2align    2
LCPI0_1:
    .long    2139095040              ## float +Inf
    .section    __TEXT,__text,regular,pure_instructions
    .globl _is_finite
    .p2align    4, 0x90
_is_finite:                
    .cfi_startproc
## BB#0:
    andps    LCPI0_0(%rip), %xmm0
    ucomiss    LCPI0_1(%rip), %xmm0
    setne    %al
    retq

---------------------------------------------------------------------

Note: 2139095040 = 0x7f800000 (check if the exponent is maxed)

I think this can be reduced to "andnps" with that constant and then ucomiss
against zero (save a load).

Alternatively, we could bring the FP value into an int register and do the
bitwise comparison there. If we have BMI, it could be something like:

movd %xmm0, %eax
andn (load bitmask), %eax, %eax
setne %al   ## if all exponent bits were not set, the value is finite

This only needs a scalar load and no explicit compare instruction is needed.

-- 
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/20160331/1fc48597/attachment.html>


More information about the llvm-bugs mailing list