-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
intrinsics::simd: add missing functions, avoid UB-triggering fast-math #121223
Conversation
Some changes occurred to the platform-builtins intrinsics. Make sure the cc @antoyo, @GuillaumeGomez, @bjorn3, @calebzulawski, @programmerjake |
...I knew about |
Most of them are unused. Should we remove those from codegen instead of adding them here? |
|
The first two are used though: rust-lang/stdarch#1533. |
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
Ah, this is blocked on rust-lang/stdarch#1529 propagating to this repo. |
Waiting for #121185. :) |
I don't think that has my recent patches included. |
library/core/src/intrinsics/simd.rs
Outdated
/// | ||
/// # Safety | ||
/// | ||
/// All input elements must be finite (i.e., not NAN and not +/- INF). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment accurate? I assume there's a std::arch reason but I wouldn't have picked this intrinsic name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely shouldn't be using UB-causing fast-math flags without clearly having _fast
in the name. Can we fix this intrinsic to only use the reassoc
flag instead of the fast
flag? This will eliminate the potential for UB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also fix rust-lang/stdarch#1533.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is accurate wrt the current implementation in the LLVM codegen backend.
Let's use rust-lang/stdarch#1533 to discuss alternative implementations.
This comment has been minimized.
This comment has been minimized.
12a2f41
to
f70538c
Compare
@bors r+ |
intrinsics::simd: add missing functions Turns out stdarch declares a bunch more SIMD intrinsics that are still missing from libcore. I hope I got the docs and in particular the safety requirements right for these "unordered" and "nanless" intrinsics. Many of these are unused even in stdarch, but they are implemented in the codegen backend, so we may as well list them here. r? `@Amanieu` Cc `@calebzulawski` `@workingjubilee`
2ab96fe
to
f70538c
Compare
Rollup of 8 pull requests Successful merges: - rust-lang#121167 (resolve: Scale back unloading of speculatively loaded crates) - rust-lang#121196 (Always inline check in `assert_unsafe_precondition` with cfg(debug_assertions)) - rust-lang#121206 (Top level error handling) - rust-lang#121223 (intrinsics::simd: add missing functions) - rust-lang#121241 (Implement `NonZero` traits generically.) - rust-lang#121242 (Generate `getelementptr` instead of `inttoptr` for `ptr::invalid`) - rust-lang#121278 (Remove the "codegen" profile from bootstrap) - rust-lang#121286 (Rename `ConstPropLint` to `KnownPanicsLint`) r? `@ghost` `@rustbot` modify labels: rollup
f70538c
to
de3cdf8
Compare
… all fast-math flags
4cca7c6
to
2df74bb
Compare
@bors r=Amanieu |
unsafe { | ||
let instr = llvm::LLVMRustBuildVectorReduceFAdd(self.llbuilder, acc, src); | ||
llvm::LLVMRustSetAlgebraicMath(instr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saethlin you changed these to "algebraic", but I think they should be just "reassoc" to match what clang does. (And even that is questionable, see rust-lang/stdarch#1533. But that's a separate issue.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe the "algebraic" implementation is technically wrong. But it was an improvement to land because it doesn't explode so dramatically :p
This comment has been minimized.
This comment has been minimized.
2df74bb
to
64efe80
Compare
@bors r=Amanieu |
intrinsics::simd: add missing functions, avoid UB-triggering fast-math Turns out stdarch declares a bunch more SIMD intrinsics that are still missing from libcore. I hope I got the docs and in particular the safety requirements right for these "unordered" and "nanless" intrinsics. Many of these are unused even in stdarch, but they are implemented in the codegen backend, so we may as well list them here. r? `@Amanieu` Cc `@calebzulawski` `@workingjubilee`
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
64efe80
to
07b6240
Compare
@bors r=Amanieu |
☀️ Test successful - checks-actions |
Finished benchmarking commit (c1b478e): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 650.169s -> 649.414s (-0.12%) |
Turns out stdarch declares a bunch more SIMD intrinsics that are still missing from libcore.
I hope I got the docs and in particular the safety requirements right for these "unordered" and "nanless" intrinsics.
Many of these are unused even in stdarch, but they are implemented in the codegen backend, so we may as well list them here.
r? @Amanieu
Cc @calebzulawski @workingjubilee