llvm / llvm/llvm-project

[X86] `fptoui float ... to i128` generates invalid libcall

Open
#189,404 2 comments 0 reactions 0 assignees View on GitHub
backend:X86
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```llvm
define i32 @square(float) local_unnamed_addr #0 {
%2 = fptoui float %0 to i128
%3 = trunc i128 %2 to i32
ret i32 %3
}
```

this codegens via `llc -march=x86` to:
```assembly
square: # @square
sub esp, 44
fld dword ptr [esp + 48]
fstp dword ptr [esp + 4]
lea eax, [esp + 16]
mov dword ptr [esp], eax
call __fixunssfti
sub esp, 4
mov eax, dword ptr [esp + 16]
add esp, 44
ret
```

but `__fixunssfti` is not available in compiler-rt on x86-32. Similar libcalls occur with `fptosi`, `sitofp`, and `uitofp`.

https://godbolt.org/z/fK4c93ffv

Likely also an issue on ARMv7 and AArch64 ILP32. Since https://github.com/llvm/llvm-project/commit/89f36dd8f32f85bfaf19dfa2cbb12d6622727bfb is available, should the x86 target configure `MaxLargeFPConvertBitWidthSupported` to 64 by default on the 32-bit subtarget?

Compiling with `-march=x86 --expand-fp-convert-bits=64` resolves the issue (as expected).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.