<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/68610>68610</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [compiler-rt][X86_64] `__truncdfhf2` returns wrong value
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jmmartinez
      </td>
    </tr>
</table>

<pre>
    Hello,

I've encountered a problem when converting a `double` into a `half` and linking against compiler-rt.

My system is Ubuntu on x86_64. I'm compiling LLVM's main branch with `CMAKE_BUILD_TYPE=Release`.

Consider the following code:

```cpp
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]) {
  double d = atof(argv[1]);
  _Float16 h = d;
  double dd = h;
  printf("d: %lf\n", dd);
  return 0;
}
```

If I compile and executed this code with using compiler-rt as rtlib:

```bash
> clang++ -O0 -o a.out -rtlib=compiler-rt 238491.cpp
> ./a.out 4
d: 0.000000
```

In contrast, if I compile with the default rtlib I get the expected output:

```bash
> clang++ -O0 -o a.out 238491.cpp
> ./a.out 4
d: 4.000000
```

The issue also dissapears if I compile LLVM with `CMAKE_BUILD_TYPE=Debug`.

I've run the code in a debugger and it seems that the value of `h` coming from `__truncdfhf2` is `0.0`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVN-P4jYQ_mvMy4jI2CTAAw8LLOqqu2pV3VXtE3LsSeKrYyP_WHb711d2uD321LtWOoQCGY8_-_vmmxEh6N4ibkm9I_VhJlIcnN9-Gkfho7b496x16nX7ExrjCNsTeiD0bno-ELZ6RkArXbIRPSoQcPauNTjCZUAL0tlnzDA9CCANVS61BklDQdvoptggTJcjwiow2v5VknuhbYgg3XjWBv3cx-r25KdXCK8h4gg6wMc22ZjAWXhZN6dmWUG-2HjdnOEeH39_ImwVYBTaQuuFlQNcdBzy-funu5_vT7uP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