-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Increase vtable layout size #123572
Increase vtable layout size #123572
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Increase vtable layout size This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example). Unfortunately it doesn't help with e.g. FnMut (due to FnOnce occupying a slot in the supertraits there) but seems like potentially still a win for simpler cases. ```rust #[no_mangle] pub fn foo(elements: &[u32], callback: &mut dyn Callback) { for element in elements.iter() { if *element != 0 { callback.call(*element); } } } pub trait Callback { fn call(&mut self, _: u32); } ``` Simplifying a bit (e.g., numbering ends up different): ```diff ; Function Attrs: nonlazybind uwtable -define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(24) %callback.1) unnamed_addr #0 { +define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(32) %callback.1) unnamed_addr #0 { start: %_15 = getelementptr inbounds i32, ptr %elements.0, i64 %elements.1 `@@` -13,4 +13,5 `@@` bb4.lr.ph: ; preds = %start %1 = getelementptr inbounds i8, ptr %callback.1, i64 24 + %2 = load ptr, ptr %1, align 8, !nonnull !3 br label %bb4 bb6: ; preds = %bb4 - %4 = load ptr, ptr %1, align 8, !invariant.load !3, !nonnull !3 - tail call void %4(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) + tail call void %2(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) br label %bb7 } ```
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (dab7be8): comparison URL. Overall result: ❌ regressions - 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: 670.181s -> 668.562s (-0.24%) |
12d2363
to
26954e7
Compare
@bors try @rust-timer queue Pushed what I hope is a fix for the cycle error and an improvement on the accuracy of the approximation that catches FnMut (and other cases) as well. Let's re-run perf since it is a more expensive computation now. |
This comment has been minimized.
This comment has been minimized.
Increase vtable layout size This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example). The calculation here is an under-approximation but works for simple trait hierarchies (e.g., FnMut will be improved). We have a runtime assert that the approximation is accurate, so there's no risk of UB as a result of getting this wrong. ```rust #[no_mangle] pub fn foo(elements: &[u32], callback: &mut dyn Callback) { for element in elements.iter() { if *element != 0 { callback.call(*element); } } } pub trait Callback { fn call(&mut self, _: u32); } ``` Simplifying a bit (e.g., numbering ends up different): ```diff ; Function Attrs: nonlazybind uwtable -define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(24) %callback.1) unnamed_addr #0 { +define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(32) %callback.1) unnamed_addr #0 { start: %_15 = getelementptr inbounds i32, ptr %elements.0, i64 %elements.1 `@@` -13,4 +13,5 `@@` bb4.lr.ph: ; preds = %start %1 = getelementptr inbounds i8, ptr %callback.1, i64 24 + %2 = load ptr, ptr %1, align 8, !nonnull !3 br label %bb4 bb6: ; preds = %bb4 - %4 = load ptr, ptr %1, align 8, !invariant.load !3, !nonnull !3 - tail call void %4(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) + tail call void %2(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) br label %bb7 } ```
This comment has been minimized.
This comment has been minimized.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (3d8cc34): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @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)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. 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: 666.9s -> 666.636s (-0.04%) |
26954e7
to
f4e1921
Compare
Regressions look to be just recently introduced bimodality/noise. This should be ready for review (last push is just a typo fix). |
r? compiler |
@bors r+ |
…i-obk Increase vtable layout size This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example). The calculation here is an under-approximation but works for simple trait hierarchies (e.g., FnMut will be improved). We have a runtime assert that the approximation is accurate, so there's no risk of UB as a result of getting this wrong. ```rust #[no_mangle] pub fn foo(elements: &[u32], callback: &mut dyn Callback) { for element in elements.iter() { if *element != 0 { callback.call(*element); } } } pub trait Callback { fn call(&mut self, _: u32); } ``` Simplifying a bit (e.g., numbering ends up different): ```diff ; Function Attrs: nonlazybind uwtable -define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(24) %callback.1) unnamed_addr #0 { +define void `@foo(ptr` noalias noundef nonnull readonly align 4 %elements.0, i64 noundef %elements.1, ptr noundef nonnull align 1 %callback.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(32) %callback.1) unnamed_addr #0 { start: %_15 = getelementptr inbounds i32, ptr %elements.0, i64 %elements.1 `@@` -13,4 +13,5 `@@` bb4.lr.ph: ; preds = %start %1 = getelementptr inbounds i8, ptr %callback.1, i64 24 + %2 = load ptr, ptr %1, align 8, !nonnull !3 br label %bb4 bb6: ; preds = %bb4 - %4 = load ptr, ptr %1, align 8, !invariant.load !3, !nonnull !3 - tail call void %4(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) + tail call void %2(ptr noundef nonnull align 1 %callback.0, i32 noundef %_9) br label %bb7 } ```
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors r- (manually r- because the tree looks wonky with some PRs that shouldn't be elligble for rollup) |
☔ The latest upstream changes (presumably #125665) made this pull request unmergeable. Please resolve the merge conflicts. |
This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example).
fbc3dff
to
8b7f67f
Compare
This comment has been minimized.
This comment has been minimized.
8b7f67f
to
95e0732
Compare
@bors r=oli-obk Rebased and fixed a test (off by one after vtable sizes are now more precise, I think). |
☀️ Test successful - checks-actions |
Finished benchmarking commit (f2208b3): comparison URL. Overall result: ✅ improvements - 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)Results (primary -1.1%)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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary -0.1%, secondary -0.2%)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.
Bootstrap: 667.575s -> 668.781s (0.18%) |
This improves LLVM's codegen by allowing vtable loads to be hoisted out of loops (as just one example). The calculation here is an under-approximation but works for simple trait hierarchies (e.g., FnMut will be improved). We have a runtime assert that the approximation is accurate, so there's no risk of UB as a result of getting this wrong.
Simplifying a bit (e.g., numbering ends up different):