-
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
implement SIMD gather/scatter via vector getelementptr #95961
Conversation
Thank you for submitting a new PR for the library teams! If this PR contains a stabilization of a library feature that has not already completed FCP in its tracking issue, introduces new or changes existing unstable library APIs, or changes our public documentation in ways that create new stability guarantees then please comment with |
(rust-highfive has picked a reviewer for you, use r? to override) |
let layout = bx.layout_of(pointee.ty); | ||
let ptrs = args[0].immediate(); | ||
let offsets = args[1].immediate(); | ||
return Ok(bx.gep(bx.backend_type(layout), ptrs, &[offsets])); |
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.
Does gep
type check this? Or can calling the intrinsic improperly result in an LLVM codegen error?
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.
I don't know, so we should probably add a codegen test rather than finding out the hard way. gep
isn't that complex but it's known to ambush unwary compiler engineers when they turn their back on it. I can help draft such a codegen test if necessary.
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 does about as much checking as the arith_offset
intrinsic, I think. The one extra check there is that the offsets
must be ptr-sized integers, which arith_offset
enforces via the type signature (but I am not sure if anything checks that type signature). I can try to add that here.
What kind of codegen test are you looking for?
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.
I added a check for the integer type in the second operand.
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.
Oh, I mostly just want to see with this that we generate a vector of pointers to the given type and then gep it like we Damn Well Should and don't suddenly somehow revert to scalar operations or something like that. A smoke test that the suite of intrinsics used to do a gather or scatter compiles correctly, basically, and that the types don't go suddenly weird on us.
This does about as much checking as the arith_offset intrinsic, I think. The one extra check there is that the offsets must be ptr-sized integers, which arith_offset enforces via the type signature (but I am not sure if anything checks that type signature). I can try to add that here.
For the #[repr(simd)]
types, while we do type-checking in rustc's front and "middle" phases to guarantee the input vector types are valid machine vector types, you can assume that it probably has bypassed any sensible checking like "is this even actually a pointer?" and is relying heavily on correct usage. Thus we would like to error during monomorphization on anything fishy.
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.
That is to say:
It is important to error in mono (as you do here) because I do not believe we have anything before this step that would even enforce that the first arg to simd_arith_offset
would be a vector of pointers.
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.
Oh, I mostly just want to see with this that we generate a vector of pointers to the given type
Okay... I'll try my best but I barely ever work with codegen tests so I am not even sure of the syntax to use.^^ Is there another portable-simd codegen test I could model this off of?
Should it go through portable-simd APIs or call the intrinsics directly?
A smoke test that the suite of intrinsics used to do a gather or scatter compiles correctly, basically, and that the types don't go suddenly weird on us.
We have the doctests as smoke tests as well. ;)
879e7c2
to
e886dc5
Compare
All right, I added a codegen test. I don't know if that's what you were asking for, though.^^ |
The functions using this new intrinsic are marked as |
Oh yes, that is exactly what I had in mind! The doctests are functional tests, which are good, but sometimes people noodle around with the ABI in a way that causes codegen-level regressions even though they don't impact functionality. They usually do it because it improves codegen in one place, but it's rarely worth it if it causes a regression on basic codegen elsewhere. These should rarely happen with what we are doing, but I have started becoming more concerned about paying close attention to what is happening with our emitted LLVMIR. So as the test passes, and with bjorn3's assent, let's get those on the road. @bors r+ rollup=always |
📌 Commit eb905c0 has been approved by |
…ubilee implement SIMD gather/scatter via vector getelementptr Fixes rust-lang/portable-simd#271 However, I don't *really* know what I am doing here... Cc `@workingjubilee` `@calebzulawski` I didn't do anything for cranelift -- `@bjorn3` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
…ubilee implement SIMD gather/scatter via vector getelementptr Fixes rust-lang/portable-simd#271 However, I don't *really* know what I am doing here... Cc ``@workingjubilee`` ``@calebzulawski`` I didn't do anything for cranelift -- ``@bjorn3`` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
…ubilee implement SIMD gather/scatter via vector getelementptr Fixes rust-lang/portable-simd#271 However, I don't *really* know what I am doing here... Cc ```@workingjubilee``` ```@calebzulawski``` I didn't do anything for cranelift -- ```@bjorn3``` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
D'oh, of course, that codegen test should probably be made 64bit-only. |
eb905c0
to
73f9571
Compare
@bors r=workingjubilee |
📌 Commit 73f9571 has been approved by |
…ubilee implement SIMD gather/scatter via vector getelementptr Fixes rust-lang/portable-simd#271 However, I don't *really* know what I am doing here... Cc `@workingjubilee` `@calebzulawski` I didn't do anything for cranelift -- `@bjorn3` not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)
Rollup of 9 pull requests Successful merges: - rust-lang#93969 (Only add codegen backend to dep info if -Zbinary-dep-depinfo is used) - rust-lang#94605 (Add missing links in platform support docs) - rust-lang#95372 (make unaligned_references lint deny-by-default) - rust-lang#95859 (Improve diagnostics for unterminated nested block comment) - rust-lang#95961 (implement SIMD gather/scatter via vector getelementptr) - rust-lang#96004 (Consider lifetimes when comparing types for equality in MIR validator) - rust-lang#96050 (Remove some now-dead code that was only relevant before deaggregation.) - rust-lang#96070 ([test] Add test cases for untested functions for BTreeMap) - rust-lang#96099 (MaybeUninit array cleanup) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes rust-lang/portable-simd#271
However, I don't really know what I am doing here... Cc @workingjubilee @calebzulawski
I didn't do anything for cranelift -- @bjorn3 not sure if it's okay for that backend to temporarily break. I'm happy to cherry-pick a patch that adds cranelift support. :)