-
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
Stop using LLVM struct types for byval/sret #122050
Conversation
This avoids depending on LLVM's struct types to determine the size of the byval/sret slot.
// CHECK: %int16x4x2_t = type { <4 x i16>, <4 x i16> } | ||
#[no_mangle] | ||
fn takes_int16x4x2_t(t: int16x4x2_t) -> int16x4x2_t { | ||
extern "unadjusted" fn takes_int16x4x2_t(t: int16x4x2_t) -> int16x4x2_t { | ||
t | ||
} |
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 test only indirectly used the struct type via byval
(so it would be removed by these changes), but the original motivation (#87254) was for the unadjusted
ABI, where we use the struct type directly and pass the vectors by value. Changed it to test that.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Stop using LLVM struct types for byval/sret For `byval`, and `sret`, the type has no semantic meaning, only the size matters\*†. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. \*: The alignment would also matter if we didn't explicitly specify it. From what I can tell, we always specified the alignment for `sret`; for `byval`, we didn't until rust-lang#112157. †: For `byval`, the hidden copy may be impacted by padding in the LLVM struct type, i.e. padding bytes may not be copied. (I'm not sure if this is done today, but I think it would be legal.) But we manually pad our LLVM struct types specifically to avoid there ever being LLVM-visible padding, so that shouldn't be an issue. Split out from rust-lang#121577. r? `@nikic`
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d5b8881): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never 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 sizeResultsThis 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.
Bootstrap: 646.18s -> 643.479s (-0.42%) |
@bors r+ rollup=never |
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.
Sounds like the docs at https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_llvm/abi/enum.PassMode.html#variant.Indirect should be updated then? Currently they say
This corresponds to the byval LLVM argument attribute (using the Rust type of this argument).
The parenthetical is no longer true with this patch.
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.
Removed the parenthetical. The important part is that byval
is used, the specific type is not so important (it could be [N x i8]
, iM
, the Rust struct type, etc.)
I added that comment when trying to figure out where Rust types leak into the ABI, an effort that found a few subtle ABI bugs. So I think there can never be enough details in these ABI comments.
In particular from the PR description it seems to be relevant that it has no padding? So i guess the pertinent information is: the the argument will be passed as one contiguous value on the stack (including all padding), with the alignment of the Rust type of the argument, and the offset determined by the system ABI.
|
Added more info. Your point makes sense, especially as the alignment does not actually match the Rust type, nor is it guaranteed to be higher or lower than the Rust type's alignment. Instead, it's...complicated. |
Oh wow.... and you're sure that's sound? Nothing is then relying on that alignment matching the Rust type alignment? |
Using a different alignment is fine in terms of Rust semantics because the
We handle the reverse situation already--if you have a type where the Rust alignment is lower than the As for this PR, it doesn't change the status quo. Before this PR it would generate Edit: opened #122212 |
I don't understand how that is possible. If the alignment differs between the Rust type and the C type, then things will go wrong in a bunch of places, not just for byval argument passing. Or is it the case some some ABIs have entirely independent alignments for when an argument is "in memory" vs passed on the stack? Unfortunately the PR links to "this comment" by @eddyb but the link is broken, so it's hard to read up on what happened. (EDIT: Ah, found it.) Anyway all that information should make it into suitable rustc comments as it'll be easier to find there.
Ah, that's the key point. So I hope the codegen backend remembers this and never adds a Rust-type-based alignment annotation when working on these pointers. @bors r- (to update the labels, this already left the queue when you pushed) |
@bors r+ |
Stop using LLVM struct types for byval/sret For `byval` and `sret`, the type has no semantic meaning, only the size matters\*†. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. \*: The alignment would matter, if we didn't explicitly specify it. From what I can tell, we always specified the alignment for `sret`; for `byval`, we didn't until rust-lang#112157. †: For `byval`, the hidden copy may be impacted by padding in the LLVM struct type, i.e. padding bytes may not be copied. (I'm not sure if this is done today, but I think it would be legal.) But we manually pad our LLVM struct types specifically to avoid there ever being LLVM-visible padding, so that shouldn't be an issue. Split out from rust-lang#121577. r? `@nikic`
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Ah, and of course if those tests never ran, or only ran on their target-specific builders, they wouldn't have ran on the x86 nopt builders either. |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (a6d93ac): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @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 sizeResultsThis 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.
Bootstrap: 647.708s -> 645.581s (-0.33%) |
Those regressions (and probably improvements) are noise, they were undone in the next merge. This is so direct that I feel justified to do @rustbot label perf-regression-triaged |
For
byval
andsret
, the type has no semantic meaning, only the size matters*†. Using[N x i8]
is a more direct way to specify that we wantN
bytes, and avoids relying on LLVM's struct layout.*: The alignment would matter, if we didn't explicitly specify it. From what I can tell, we always specified the alignment for
sret
; forbyval
, we didn't until #112157.†: For
byval
, the hidden copy may be impacted by padding in the LLVM struct type, i.e. padding bytes may not be copied. (I'm not sure if this is done today, but I think it would be legal.) But we manually pad our LLVM struct types specifically to avoid there ever being LLVM-visible padding, so that shouldn't be an issue.Split out from #121577.
r? @nikic