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: unassignedb...@nondot.org Reporter: spatel+l...@rotateright.com CC: llvm-bugs@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.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs