Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport LLVM apfloat commit to rustc_apfloat #77368

Merged
merged 2 commits into from
Oct 4, 2020
Merged

Conversation

est31
Copy link
Member

@est31 est31 commented Sep 30, 2020

Backports LLVM commit: llvm/llvm-project@e34bd1e

Fixes #69532

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 30, 2020
Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, this is pretty clearly still wrong... Disappointing... I'll try and file an upstream bug about it when I have more time :(.

@thomcc
Copy link
Member

thomcc commented Sep 30, 2020

Can you remove the Fixes comment? This will fix the listed issue in one case, but not all. See #69532 (comment) for more details.

@est31
Copy link
Member Author

est31 commented Sep 30, 2020

@thomcc it fixes the example at the top of #69532 . Maybe file a different issue for the general case? IDK.

@RalfJung
Copy link
Member

Can you remove the Fixes comment? This will fix the listed issue in one case, but not all. See #69532 (comment) for more details.

Do you have a concrete example that it will not fix? Another testcase would be good.

@est31
Copy link
Member Author

est31 commented Sep 30, 2020

Hmmm I think we should wait until this LLVM MR that @thomcc linked to is merged: https://reviews.llvm.org/D88238

Then we can backport that.

I'm not sure I agree with the suggestion to change usage sites, pointed out by @thomcc here, because the one they refer to mainly concerns floating point parsing of LLVM IR. LLVM has hexadecimal "raw" ways to specify float literals with some type inferrence, but in Rust you can only specify floats by their decimal fraction.

@est31
Copy link
Member Author

est31 commented Oct 3, 2020

Now the commit has made it to LLVM master.

r? @varkor

// don't currently do it. You're really supposed to get
// an invalid operation signal at runtime, but nobody does that.
status = Status::OK;
// Convert of sNaN creates qNaN and raises an exception (invalid op).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what "raises an exception" means here, but wouldn't this mean the cast fails when run in Miri?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's the purpose of signaling NaNs. Quoting Wikipedia:

Signaling NaNs, or sNaNs, are special forms of a NaN that, when consumed by most operations, should raise the invalid operation exception and then, if appropriate, be "quieted" into a qNaN that may then propagate.

This is precisely what we (and LLVM) do here :).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my understanding that this is generally not implemented, i.e., sNaNs behave like qNaNs with modern compilers on modern hardware? But maybe I misunderstood.

Given that your new testcases passes, it does not seem like this "exception" actually does anything in Miri though, so I guess it's okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah by default trapping is off, but it can be enabled by e.g. feenableexcept. If trapping is off, only some exception flags are set in a specific "status word" register, readable by e.g. _statusfp on Windows (couldn't find the unix analog).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On x86, it's the fstsw instruction.

Backports LLVM commit:

    [APFloat] convert SNaN to QNaN in convert() and raise Invalid signal

llvm/llvm-project@149f5b5

SNaN to QNaN conversion also matches what my Intel x86_64 hardware does.
@varkor
Copy link
Member

varkor commented Oct 4, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Oct 4, 2020

📌 Commit d010809 has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 4, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 4, 2020
…as-schievink

Rollup of 8 pull requests

Successful merges:

 - rust-lang#77072 (Minor `hash_map` doc adjustments + item attribute orderings)
 - rust-lang#77368 (Backport LLVM apfloat commit to rustc_apfloat)
 - rust-lang#77445 (BTreeMap: complete the compile-time test_variance test case)
 - rust-lang#77504 (Support vectors with fewer than 8 elements for simd_select_bitmask)
 - rust-lang#77513 (Change DocFragments from enum variant fields to structs with a nested enum)
 - rust-lang#77518 (Only use Fira Sans for the first `td` in item lists)
 - rust-lang#77521 (Move target feature whitelist from cg_llvm to cg_ssa)
 - rust-lang#77525 (Enable RenameReturnPlace MIR optimization on mir-opt-level >= 2)

Failed merges:

r? `@ghost`
@bors bors merged commit 9ea462f into rust-lang:master Oct 4, 2020
@rustbot rustbot added this to the 1.49.0 milestone Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Miri floating point NaN conversion issue
7 participants