<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63938>63938</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
APFloat: x87DoubleExtended pseudo-NaNs (integer_bit==0) not handled as always-signalling.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
eddyb
</td>
</tr>
</table>
<pre>
Based on https://reviews.llvm.org/D41868 (cc @labath @stephentyrone) and these snippets of `APFloat.cpp`:
https://github.com/llvm/llvm-project/blob/ef7d53731bba8c4131f519d7a4dd8cd774cfe539/llvm/lib/Support/APFloat.cpp#L3673-L3679
https://github.com/llvm/llvm-project/blob/ef7d53731bba8c4131f519d7a4dd8cd774cfe539/llvm/lib/Support/APFloat.cpp#L942-L946
I would expect the following:
* pseudo-NaNs should *always* be treated as SNaNs
* this would presumably also apply to pseudo-infinities and unnormals (all of which have in common `integer_bit == 0` w/o being subnormals, AIUI)
* not the case today: `isSignaling` ignores the integer bit and only checks the quiet bit (which a pseudo-NaN can set)
* quieting a pseudo-NaN should produce a legal QNaN (while setting the `opInvalidOp` status)
* that is, `makeQuiet` should replicate `makeNaN`'s `APInt::tcSetBit(significand, QNaNBit + 1)`
* not the case today: `makeQuiet` fails to set the integer bit, potentially leaving a pseudo-NaN behind
Or in other words, I'd expect this test to pass (currently it fails to even generate an `opInvalidOp` status):
```cxx
TEST(APFloatTest, x87PseudoNaN) {
APFloat PseudoNaN(APFloat::x87DoubleExtended(), APInt(80, {1ULL << 62, 0x7fff}));
EXPECT_TRUE(PseudoNaN.isNaN());
EXPECT_TRUE(PseudoNaN.isSignaling()); // FAIL: pseudo-NaNs aren't detected as SNaNs
// Any operation (which propagates input SNaNs while quieting them),
// `roundToIntegral` just happened to have similar tests already.
APFloat test = PseudoNaN;
APFloat::opStatus St = test.roundToIntegral(APFloat::rmTowardZero);
EXPECT_TRUE(test.isNaN());
EXPECT_FALSE(test.isSignaling()); // would FAIL if pseudo-NaNs were detected as SNaNs,
// and `makeQuiet` wasn't *also* updated
EXPECT_FALSE(test.isNegative());
EXPECT_EQ(APFloat::opInvalidOp, St); // FAIL: pseudo-NaNs aren't detected as SNaNs
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMVk1v4zgS_TX0pRBDohR9HHxw4hgwEKS712lgsZdGSSxZ7KZJLUnF8b9fkHIcx73IzABzGCBwDLM-Hl-9KhY6J3eaaMFu79jtaoaj741dkBDHZtYYcVzcoSMBRkPv_eBYtmR8zfja0oukg5sr9bKfG7tjfL3K06qogPGqbYHlicIGfR--OU9DT9ofrdHEeA2oBfieHIHTchjIOzAdsCJZfl0rg37eDgMrkpAtWbFk-TH3Tvp-bOat2TO-DgBO_24Ga35S6xlfN8o0jK-pK8VtVmZp02DV5mmWdrdpLUrMhahaUZZ529FtVl_EkcFvOw6DsSHQJSCePWZFmd2Ez_ofBqzO-c1jnRcTrOlzAwczKgH0OlDrA-HQGaXMQerdmVrGlzA4GoW5ecInB66PPowvUR3w6MJ5Q-AtoScB6GAb7CZnCHbge-lOqQZLbtxjo46AyhnAYVBH8OYthdSd1NJLclEDo9bG7lG5oBpUKqjg0Mu2hx5fCKSG1uz3RgdpSO1pR_ZHIz2wbMWyFSSsSODA-NpAQ1LvwI3NKSDj97DcfN8wXl9C1WbioUVH4I3AI8uWMbrbyp1GFagpEpA7bSy5aHtKDCFxAG20OkLbU_trOv_vKMnHU8arCT1eUAotanDkz0gCjugTEH-wPHE_WCPGlgBB0Q4VfAtnU2xFIVT0DKlZkZhho19QSfEldAw4j350V7f2PXqQkRNWJHv8Rd9C_mg_pbQ0KNmipzeDJ3wKDchLN7XlRvsgmWzp2y35O-kZr8LokJ1sUYsQOsC8iyzcQRoQFMmfov4Dng6lckEwjvw1-yHJYDxpL1GpIyjCl984bKiXWly2wRcbhGR8TxYOxorIw4bx8qIzpANPzkelootybEdrSXt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