| Issue |
169270
|
| Summary |
Suboptimal code for `std::isfinite`
|
| Labels |
llvm:instcombine,
missed-optimization
|
| Assignees |
|
| Reporter |
Kmeakin
|
[C++ code](https://godbolt.org/z/Kv6nePEjW):
```c++
auto src(float f) { return std::fabs(f) < INFINITY; }
auto tgt(float f) { return (f - f) == (f - f); }
```
AArch64 assembly:
```asm
src(float):
fmov w9, s0
mov w8, #2139095040
and w9, w9, #0x7fffffff
cmp w9, w8
cset w0, lt
ret
tgt(float):
fsub s0, s0, s0
fcmp s0, s0
cset w0, vc
ret
```
x86_64 assembly:
```asm
src(float):
movd eax, xmm0
and eax, 2147483647
cmp eax, 2139095040
setl al
ret
tgt(float):
subss xmm0, xmm0
ucomiss xmm0, xmm0
setnp al
ret
```
[LLVM IR](https://alive2.llvm.org/ce/z/SqJNMr):
```llvm
define dso_local noundef i1 @src(float)(float noundef %0) local_unnamed_addr #0 {
%2 = tail call float @llvm.fabs.f32(float %0)
%3 = fcmp one float %2, 0x7FF0000000000000
ret i1 %3
}
define dso_local noundef i1 @tgt(float)(float noundef %0) local_unnamed_addr #0 {
%2 = fsub float %0, %0
%3 = fcmp ord float %2, 0.000000e+00
ret i1 %3
}
```
This works because `inf - inf` gives `NaN` and `NaN != NaN`
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs