[compiler-rt] __truncxfhf2 incorrect values compared to --rtlib=libgcc
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The value of `__truncxfhf2` for casting long double to __fp16 appears to be incorrect with `--rtlib=compiler-rt` to `--rtlib=libgcc`, at least on x86_64 on llvm 21. This is also without `-mf16c`, though it does seem to happen with it as well.
Example program:
```
int main(void)
{
__fp16 h = 0.0f16;
long double ld = 12.34l;
h = ld;
return 0;
}
```
Compiled with clang++ and `-g --rtlib=libgcc`, in GDB I see that the value after the cast is
```
(gdb) p h
$1 = 12.344
```
which seems reasonable.
However, with `-g --rtlib=compiler-rt`, I see that the value after the cast is
```
(gdb) p h
$1 = 9504
```
which is an unreasonable value.
Contributor guide
Research direction
Reproduce the long double to __fp16 cast with the provided example using clang++ and compare --rtlib=compiler-rt against --rtlib=libgcc, with and without -mf16c. Trace the __truncxfhf2 path in compiler-rt and verify that compiler-rt produces the same reasonable value as libgcc rather than 9504.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100