<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - [x86] suboptimal codegen for isfinite IR"
href="https://llvm.org/bugs/show_bug.cgi?id=27164">27164</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[x86] suboptimal codegen for isfinite IR
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>