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

    <tr>
        <th>Summary</th>
        <td>
            `@llvm.minimumnum.f32` returns sNaN instead of qNaN on x86_64
        </td>
    </tr>

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

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

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

<pre>
    LLVM's documentation for `@llvm.minimumnum.f32` [says](https://llvm.org/docs/LangRef.html#llvm-minimumnum-intrinsic) "If both operands are NaNs (including sNaN), returns qNaN". However, on x86_64, it actually returns sNaN.

Specifically, with this test.c:
```c
#include <stdio.h>
#include <string.h>

float f32_minnumber(float x, float y);

int main() {
    float f = __builtin_nansf("");
    float g = f32_minnumber(f, f);
    float h = g + 0;

    unsigned uf, ug, uh;
 memcpy(&uf, &f, sizeof(f));
    memcpy(&ug, &g, sizeof(f));
    memcpy(&uh, &h, sizeof(f));

    printf("%x\n%x\n%x\n", uf, ug, uh);
    return 0;
}
```
and this minnumber.ll:
```llvmir
target triple = "x86_64-pc-linux-gnu"

define float @f32_minnumber(float %x, float %y) {
  %t = call float @llvm.minimumnum.f32(float %x, float %y)
  ret float %t
}
define double @f64_minnumber(double %x, double %y) {
  %t = call double @llvm.minimumnum.f32(double %x, double %y)
  ret double %t
}
define float @f32_maxnumber(float %x, float %y) {
  %t = call float @llvm.maximumnum.f32(float %x, float %y)
  ret float %t
}
define double @f64_maxnumber(double %x, double %y) {
  %t = call double @llvm.maximumnum.f32(double %x, double %y)
  ret double %t
}
```

Compiling for x86_64 gets this output:
```console
$ clang test.c minnumber.ll 
$ ./a.out 
7fa00000
7fa00000
7fe00000

```

This shows that the operands of the `f32.minimumnum` are sNaN and the result is incorrectly also sNaN.

IEEE 754-2019 says of its corresponding `minimumNumber` operattion "If both operands are NaNs, a quiet NaN is returned".

I have not tested similar variants for f64, maximumnum, or other architectures.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0Vstu6zYTfhp6M7BAURfbCy2cG_4DnD-Ltug2oChKYkGRPuQwifv0BSnFlyQN0OLUECyRc_tmOJwZ7r0ajJQNqW5IdbfiAUfrGh9Mr_wobCdXre2Ozffvv_-fsI2HzoowSYMclTXQWwekpqSkWj9P2aSMmsJkwpT1BSM1BVLdeH70pLojbDsiHjwp9oQ9EPaQJKwbCHvorPCEPXznZvhF9tmIkyasiAzrs8q1MuiU8UoQtgPC2LceWosj2IN03HQeuJPwyB89ELZVRujQKTOAf-SPhO0IuwUnMTjj4UfaYhn8z77IZ-kizRp43dZPdRkXCoELDFzr40ko6skI3RO6__UgheqViPTI_qJwBByVB5QeMxF9pPsYmPSIuGDFDEkCKW49dspmIynuPyE5ZYYTje57bTlCX7CnSRkTpjbi3c67r9H6_HmMPhY3s4wyCBNXhrBtCtYm7gPAwtsDKe7g6akNSqMyT4Yb3ydelp5F0VlgSAIfMCTrn7CPiX0Awm6AnkBFejAp3zoISTgM6X9cFExyEodjAlLPDITV6e3Vn9L2s83dlcUrmWGRGf6BzLjIjH8vs4gdnDJ4ilP1Sqpb8_HNkkvX7l0an_PpFJfN3WWqELrnpptz6RTqTOt3GRWvhnKE7pG7QSKgUwctU9QJY3Merw9irZUJr-vBhAgr-dHJXhm5nBMp6ed5lbw5pRZh1fEyjQirMNmKF-Cs6rMS8KXCpMxJPO_iKSILzs6GNjpW0r4ur4C-URbF5-UXUM_aPsf6pc4T2vP2B7jXYeWvPy-s_PU_DOsF0J8R1vdY_31YL-8FoftbOx2UjkU9Np45zWGQ6OcLYwMeAr4vvtZ4q2WqsyUIzc2wVOmrCwYLQ0bYA89swLix6TmNv_ef8u0zSnyE-VsE40f7EnFxBBzluUnZPq1JHXPkIgVjt4wNLLYZmGuABCd90AjKgzLCOicF6iNw7e1lO_p2f38Pm6pcM5rvIPbbaEWhhyTjD9akTkhquth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