-
Notifications
You must be signed in to change notification settings - Fork 107
std::simd
scatter miscompilation
#1439
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
Comments
Thanks for the report! If you want to look into this you can pass The codegen for the rustc_codegen_cranelift/src/intrinsics/simd.rs Lines 1090 to 1117 in 289a274
I can take a look at this too tomorrow. |
I made some progress in investigation. I reduced the reproducer to this: #![feature(portable_simd)]
use std::simd::{Mask, Simd};
fn main() {
let mut vec = [0; 1];
let vals = Simd::from_array([1]);
unsafe {
vals.scatter_select_ptr(Simd::from_array([vec.as_mut_ptr()]), Mask::splat(true));
}
assert_eq!(vec, [1]);
} Here is the clif for Simd::scatter_select_ptr.unopt.clif
If I didn't make a mistake in my clif analysis, the problem is that the generated code confuses
This is in agreement with the behavior of storing -1 (i.e., However, the implementation of the For testing I am still using the version of cranelift distributed via rustup in version |
|
8ab225d flipped these arguments, but in ace694c I believe I had to flip them back because of test failures [^1]. Both commits should be included in nightly-2023-12-22 due to a subtree sync on the 19th, but somehow only the first commit shows up in the git log of the rust repo. The test failures
|
This may have the same root cause as #1385. |
rust-lang/rust#119278 should fix this. |
Should be fixed in the next nightly. |
@pnevyk Can you confirm that the issue is fixed with the latest nightly? |
Yes, it works 🎉 |
The example for Simd::scatter
results in
Sort of a minimal reproducer is the following code:
which results in
(Interestingly, the second example does not cause
free(): invalid pointer
error.)Running the examples with standard LLVM backend works as expected.
If I can provide more information I will happily do so. I tried to get generated assembly using
cargo-show-asm
, but I gotLooking at the actual outputs, it seems that the problem manifests itself by
scatter
putting value -1 at indexi
andi + 1
for every (valid)i
from theidxs
vector.I would be interested in trying to fix this bug if I get some pointers to where to start. I have some basic knowledge of compilers in general and cranelift in particular.
The text was updated successfully, but these errors were encountered: