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

    <tr>
        <th>Summary</th>
        <td>
            [compiler-rt] __truncXfYf2 functions ignore the current rounding mode and always round to nearest, ties to even
        </td>
    </tr>

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

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

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

<pre>
    https://godbolt.org/z/dchq7rxe7

C code:

```c
#include <fenv.h>
#include <stdio.h>

_Float16 bar(float x) {
  return (_Float16)x;
}

int main() {
 volatile float x = 0x1.0p-25f;
  fesetround(FE_UPWARD);
 printf("%a\n", (double)bar(x));
  fesetround(FE_DOWNWARD);
 printf("%a\n", (double)bar(x));
}
```

Output with libgcc:

```
0x1p-24
0x0p+0
```

Output with compiler-rt:

```
0x0p+0
0x0p+0
```

Relevant compiler-rt source:

https://github.com/llvm/llvm-project/blob/046a17717d9c5b5385ecd914621b48bdd91524d0/compiler-rt/lib/builtins/truncsfhf2.c#L15-L17

https://github.com/llvm/llvm-project/blob/046a17717d9c5b5385ecd914621b48bdd91524d0/compiler-rt/lib/builtins/fp_trunc_impl.inc#L9-L12

cc @lntue
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVM1u5DYMfhr6IszAov8PPiSZ9SnoFgsU254GskSPVWgkV5Inkz59YU_SeNMWm0MPCxiyKf58_EiTIgR9skQtFPdQHBIxx9H51l3In_VpjM9J79RzO8Y4BcjuADvA7uRU70zcO38C7P4E7JQc_6j8lSpID5De3c4HJp2ixWtzCWV6e-SLjJm20syKGGQPA9nLfoTs078pQ1TabbXreeyME5GXrBcesB4WiV0BGwbV_c2EMU9x9pYB1q_mgM0VshcDqA7bkNpGdhbaAtbfxrk4I6I2xF5QGGQHll75Pp12WAx_x2NsoEDRu9kqwLr7dPzl5693Xw6AzZvN5LWNw4qBgIWA4sGunw9LnsrNvSHA5kZrIfSN9z8QDp-__vT_YrxV5bVn2yJ9nuM0R_ak48iM7k9S_lenb2J65dMO81chnQDv0w_Gl-48aUN-5-P3QLZxP4DyhQxdhI1bCBbc7OX7H_fdCOg4zv1eujNgZ8zl9bWbvPudZATseuN6wC7NS8GrileqkUVfZHVBUjU8L5H3ed0r1fACc5UCdlua2Bm9uPezNlHbANhFP1sZhnHAvQTMHnmxe-TVj5XjMB3XNI_6PJm9tmuize6R4zZPKRnkqbFxpkS1mWqyRiTU8gp5nVU1r5KxLeu6KLHPMW9EilWmir7MFR8450VfZ5joFlPM0wpzXvKyKPdS0sAHIQdSolRNAXlKZ6HNfiG9LKtEhzBTy9M051liRE8mrIsP0dITW7XLdBSHxLdrpfr5FJZMdYjhLUzU0awbc1uM4sCON-6_Dr8NyIbZyqidDUyfrPPE4khMzt6TjWydW21P7OwUMWEVE-ZJPIebgkXHLAlPIS6TGjWF5YouZJPZm_fb-PttXpkt7XmhfmnxrwAAAP__lAW7Gg">