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

Avoid memcpy in codegen for more types, notably Vec #112733

Closed
wants to merge 2 commits into from

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jun 17, 2023

PR #111999 set up the framework to be able to do this; this PR expands it to more types than just arrays.

Most interestingly, this allows it to work with Vec<T> and String, so swapping those no longer ends up going through stack like it does today (https://rust.godbolt.org/z/cKG7o8aaW).

And since this is done in codegen, it's not special for swap, and thus will hopefully allow types like this to better optimize in lots of places, with easier SRoA.


Draft initially, since it needs perf and I'm sure I got some of the non-opaque pointer tests wrong.

@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 17, 2023
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 17, 2023
@bors
Copy link
Contributor

bors commented Jun 17, 2023

⌛ Trying commit 58626f974068c9ec1a1da4fb7394548161e4530e with merge f9b06385bce9d1c2230e818597f5acf291b9b478...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 18, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2023
@petrochenkov
Copy link
Contributor

r? @compiler-errors

@bors
Copy link
Contributor

bors commented Jul 9, 2023

☔ The latest upstream changes (presumably #113508) made this pull request unmergeable. Please resolve the merge conflicts.

@the8472
Copy link
Member

the8472 commented Jul 19, 2023

2023-06-18T00:44:22.5513160Z Assertion failed: allocator ran out of memory

happens during Bolt profile gathering. This probably isn't a miscompilation (at least in vanilla rustc) because it rebuilds the std library several times and only fails the Nth time when doing the profiling. So I guess either the bolt instrumentation is buggy or it somehow really ends up generating a lot more data.

Maybe @Kobzol encountered an issue like this before.

@lqd
Copy link
Member

lqd commented Jul 19, 2023

We have indeed seen this while building rustc with 1 CGU, and it's a blocking issue for that work to land.

This is llvm/llvm-project#59174, and that arbitrarily low limit has been increased upstream already, in https://reviews.llvm.org/D151891. I think this now needs to appear in an LLVM release, and that we update the linux host toolchain to that version.

@Kobzol
Copy link
Contributor

Kobzol commented Jul 19, 2023

It might be a while until that happens though (weeks/months possibly), until LLVM 17 is released (+ we might have to resolve some big regressions that we have seen with it). I'll send a PR to temporarily use LLVM 16 + my patch so that this is hotfixed sooner.

@scottmcm
Copy link
Member Author

Yay, thanks to #114148 I got to go through and remove some of my codegen FIXMEs here.

@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member Author

scottmcm commented Aug 8, 2023

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 8, 2023

⌛ Trying commit 3152d29fcc86fbd5333e8e978186defd4c35d148 with merge f0bf755c1d27d7c79bbde07734abab3def1d4384...

@bors
Copy link
Contributor

bors commented Aug 8, 2023

☀️ Try build successful - checks-actions
Build commit: f0bf755c1d27d7c79bbde07734abab3def1d4384 (f0bf755c1d27d7c79bbde07734abab3def1d4384)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f0bf755c1d27d7c79bbde07734abab3def1d4384): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.0% [0.2%, 9.6%] 42
Regressions ❌
(secondary)
1.4% [0.3%, 3.0%] 8
Improvements ✅
(primary)
-1.9% [-9.1%, -0.4%] 9
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.2%] 2
All ❌✅ (primary) 1.3% [-9.1%, 9.6%] 51

Max RSS (memory usage)

Results

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.8% [1.3%, 2.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-5.0%, -2.7%] 3
All ❌✅ (primary) - - 0

Cycles

Results

This 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.

mean range count
Regressions ❌
(primary)
2.9% [0.8%, 10.3%] 24
Regressions ❌
(secondary)
2.2% [1.3%, 3.1%] 5
Improvements ✅
(primary)
-5.1% [-8.7%, -1.5%] 2
Improvements ✅
(secondary)
-3.2% [-3.3%, -3.1%] 2
All ❌✅ (primary) 2.3% [-8.7%, 10.3%] 26

Binary size

Results

This 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.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 57
Regressions ❌
(secondary)
0.4% [0.2%, 1.3%] 56
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 8
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.2%, 0.4%] 65

Bootstrap: 632.482s -> 635.485s (0.47%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 8, 2023
PR 111999 set up the framework to be able to do this; this PR expands it to more types than just arrays.

Most interestingly, this allows it to work with `Vec<T>` and `String`, so swapping those no longer ends up going through stack like it does today (<https://rust.godbolt.org/z/cKG7o8aaW>).

And since this is done in codegen, it's not special for `swap`, and thus will hopefully allow types like this to better optimize in lots of places, with easier SRoA.
@bors
Copy link
Contributor

bors commented Aug 26, 2023

☔ The latest upstream changes (presumably #115236) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@scottmcm any updates on this?

@scottmcm
Copy link
Member Author

scottmcm commented May 4, 2024

Given #123185, I no longer think this is a good idea.

Things like https://github.com/rust-lang/rust/blob/master/tests/assembly/x86_64-typed-swap.rs have been added since I was working on this that better check for what's important here.

@scottmcm scottmcm closed this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missed code elimination with std::mem::replace/std::mem::swap