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

wasm: Make simd types passed via indirection again #85966

Merged
merged 1 commit into from
Jun 5, 2021

Conversation

alexcrichton
Copy link
Member

This commit updates wasm target specs to use simd_types_indirect: true
again. Long ago this was added since wasm simd types were always
translated to v128 under-the-hood in LLVM, meaning that it didn't
matter whether that target feature was enabled or not. Now, however,
v128 is conditionally used in codegen depending on target features
enabled, meaning that it's possible to get linker errors about different
signatures in code that correctly uses simd types. The fix is the same
as for all other platforms, which is to pass the type indirectly.

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(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 Jun 3, 2021
@alexcrichton
Copy link
Member Author

It's worth pointing out that this may have actually always been a bug and when I first implemented this I just didn't realize the impact of what I was doing. In any case the test added here fails on wasm today with a linking error, but I dont believe that it should.

It's possible perhaps to fix this in the codegen layer of LLVM by automatically enabling the simd128 feature whenever a vector type is used in the parameter/argument list, but that I think is more complicated than implementing this fix which works the same for all platforms. Note that performance isn't expected to be affected here since simd intrinsics rely on inlining for performance anyway, so it's extremely rare in practice to actually have a function call with a v128 argument or return value on the hot path.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

This commit updates wasm target specs to use `simd_types_indirect: true`
again. Long ago this was added since wasm simd types were always
translated to `v128` under-the-hood in LLVM, meaning that it didn't
matter whether that target feature was enabled or not. Now, however,
`v128` is conditionally used in codegen depending on target features
enabled, meaning that it's possible to get linker errors about different
signatures in code that correctly uses simd types. The fix is the same
as for all other platforms, which is to pass the type indirectly.
@workingjubilee
Copy link
Member

I discussed this extensively with Alex yesterday off-sides to clarify my understanding of the situation, but today I realized that constituted a review of the code and really, of the situation as-is, which this PR essentially is a confirmation of. Some comments to summarize that (chat|review):

  1. A possible performance hit mostly isn't an issue here because whether wasm SIMD improves performance is up to the wasm runtime, not us, so our main concern is just making sure we don't pessimize things unduly.
  2. LLVM should see through it anyways. If LLVM doesn't see through it, this is a concern on other architectures as well, so wasm is nothing special here.
  3. Automatically enabling features might be an awkward solution, even if implemented, due to concerns about whether we correctly eschew inserting SIMD instructions when the programmer does not desire them. These concerns would be extremely minimal for wasm, tho'.
  4. Ultimately the inciting issue to pay attention to, and the "real" one for someone to solve in future work, is -C target-feature/-C target-cpu are unsound #64609

@bors r+

@bors
Copy link
Contributor

bors commented Jun 4, 2021

📌 Commit 55769a5 has been approved by workingjubilee

@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 Jun 4, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 4, 2021
Rollup of 10 pull requests

Successful merges:

 - rust-lang#83653 (Remove unused code from `rustc_data_structures::sync`)
 - rust-lang#84466 (rustdoc: Remove `PrimitiveType::{to_url_str, as_str}`)
 - rust-lang#84880 (Make match in `register_res` easier to read)
 - rust-lang#84942 (rustdoc: link to stable/beta docs consistently in documentation)
 - rust-lang#85853 (Warn against boxed DST in `improper_ctypes_definitions` lint)
 - rust-lang#85939 (Fix suggestion for removing &mut from &mut macro!().)
 - rust-lang#85966 (wasm: Make simd types passed via indirection again)
 - rust-lang#85979 (don't suggest unsized indirection in where-clauses)
 - rust-lang#85983 (Update to semver 1.0.3)
 - rust-lang#85988 (Note that `ninja = false` goes under `[llvm]`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5d30ab8 into rust-lang:master Jun 5, 2021
@rustbot rustbot added this to the 1.54.0 milestone Jun 5, 2021
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.

7 participants