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

cg_llvm: stop identifying ADTs in LLVM IR #114350

Merged
merged 1 commit into from Aug 4, 2023
Merged

Conversation

erikdesjardins
Copy link
Contributor

This is an extension of #94107. It may be a minor perf win.

Fixes #96242.

Now that we use opaque pointers, ADTs can no longer be recursive, so we
do not need to name them. Previously, this would be necessary if you had
a struct like

struct Foo(Box<Foo>, u64, u64);

which would be represented with something like

%Foo = type { %Foo*, i64, i64 }

which is now just

{ ptr, i64, i64 }

r? @tmiasko

Now that we use opaque pointers, ADTs can no longer be recursive, so we
do not need to name them. Previously, this would be necessary if you had
a struct like

```rs
struct Foo(Box<Foo>, u64, u64);
```

which would be represented with something like

```ll
%Foo = type { %Foo*, i64, i64 }
```

which is now just

```ll
{ ptr, i64, i64 }
```
@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 Aug 1, 2023
@workingjubilee
Copy link
Contributor

workingjubilee commented Aug 1, 2023

@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 Aug 1, 2023
@workingjubilee
Copy link
Contributor

whoops, uhh
@bors try

@bors
Copy link
Contributor

bors commented Aug 1, 2023

⌛ Trying commit 1d7f728 with merge 0c56080e7cdb00fc640662bd2954f5a58254a3f9...

@bors
Copy link
Contributor

bors commented Aug 2, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0c56080e7cdb00fc640662bd2954f5a58254a3f9): 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)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
0.4% [0.3%, 0.5%] 2
Improvements ✅
(primary)
-0.8% [-1.2%, -0.3%] 5
Improvements ✅
(secondary)
-1.2% [-1.6%, -0.8%] 2
All ❌✅ (primary) -0.6% [-1.2%, 0.4%] 6

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)
- - 0
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
-3.8% [-3.8%, -3.8%] 1
All ❌✅ (primary) -1.3% [-1.3%, -1.3%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-2.6%, -0.2%] 2
All ❌✅ (primary) - - 0

Bootstrap: missing data

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 2, 2023
@erikdesjardins
Copy link
Contributor Author

Perf shows a ~1% improvement to a few opt builds, which is about what I expected.

But then also a 0.5% regression to 3 doc builds. This doesn't make sense, rustdoc shouldn't be doing any codegen (I hope), and this change should not be able to impact optimizations. I suspect it is something like: changing some struct types from being named to unnamed changes module hashes during LTO, which slightly perturbs some code in rustdoc, making it slower if we're unlucky.

Cachegrind diff:

Files compared:   results/cgfilt-d12c6e947ceacf3b22c154caf9532b390d8dc88a-ucd-Doc-Full; results/cgfilt-0c56080e7cdb00fc640662bd2954f5a58254a3f9-ucd-Doc-Full
...

--------------------------------------------------------------------------------
Ir         
--------------------------------------------------------------------------------
39,529,196  PROGRAM TOTALS

--------------------------------------------------------------------------------
Ir          file:function
--------------------------------------------------------------------------------
49,843,901  ???:<rustc_infer::infer::freshen::TypeFreshener as rustc_type_ir::fold::FallibleTypeFolder<rustc_middle::ty::context::TyCtxt>>::try_fold_ty
-6,447,963  ???:<rustc_middle::ty::Ty as rustc_type_ir::fold::TypeSuperFoldable<rustc_middle::ty::context::TyCtxt>>::try_super_fold_with::<rustc_infer::infer::freshen::TypeFreshener>
 1,377,686  ???:<rustc_middle::ty::Ty as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
-1,214,742  ???:<rustc_middle::hir::map::ItemCollector as rustc_hir::intravisit::Visitor>::visit_expr
 1,209,392  ???:<rustc_span::hygiene::SyntaxContext as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
-1,133,433  ???:<rustc_middle::ty::generics::GenericParamDef as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
-1,115,806  ???:<rustc_span::hygiene::SyntaxContextData as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
-1,051,024  ???:<rustc_arena::TypedArena<rustc_span::source_map::Spanned<rustc_ast::ast::LitKind>> as core::ops::drop::Drop>::drop
...

Looks like some inlining decision changes near TypeFreshener. I could try adding some more inline annotations on try_fold_ty (TypeFreshener::fold_ty is #[inline] already) or other nearby functions, but given how sensitive the type folding code is, and the small number and magnitude of regressions, I am not inclined to do so.

@workingjubilee
Copy link
Contributor

Rustdoc has been known to evince severe regressions merely from adding library API before, so.

@erikdesjardins
Copy link
Contributor Author

erikdesjardins commented Aug 3, 2023

Hmm, yeah, looking at the three doc builds that regressed, they've been jumping up and down by the same magnitude seen in this PR:

webrender-2022-doc
This PR: +0.35%
Recent oscillations: +/-0.3%
image

ucd-doc
This PR: +0.45%
Recent oscillations: +/-0.5%
image

match-stress-doc
This PR: +0.33%
Recent oscillations: +/-0.3%
image

I think, then, I'm justified in doing
@rustbot label +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Aug 3, 2023
@tmiasko
Copy link
Contributor

tmiasko commented Aug 4, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Aug 4, 2023

📌 Commit 1d7f728 has been approved by tmiasko

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 4, 2023
@bors
Copy link
Contributor

bors commented Aug 4, 2023

⌛ Testing commit 1d7f728 with merge 73dc6f0...

@bors
Copy link
Contributor

bors commented Aug 4, 2023

☀️ Test successful - checks-actions
Approved by: tmiasko
Pushing 73dc6f0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 4, 2023
@bors bors merged commit 73dc6f0 into rust-lang:master Aug 4, 2023
12 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 4, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (73dc6f0): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-1.2%, -0.6%] 5
Improvements ✅
(secondary)
-1.1% [-1.5%, -0.6%] 6
All ❌✅ (primary) -0.8% [-1.2%, -0.6%] 5

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)
4.4% [4.4%, 4.4%] 1
Regressions ❌
(secondary)
2.5% [1.7%, 2.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 4.4% [4.4%, 4.4%] 1

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)
4.0% [2.9%, 5.3%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.0% [2.9%, 5.3%] 6

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 3
Improvements ✅
(secondary)
-1.4% [-2.6%, -0.2%] 2
All ❌✅ (primary) -0.0% [-0.0%, -0.0%] 3

Bootstrap: 649.336s -> 647.034s (-0.35%)

@rustbot rustbot removed the perf-regression Performance regression. label Aug 4, 2023
@erikdesjardins erikdesjardins deleted the ident branch August 4, 2023 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

When we switch to opaque pointers, stop identifying ADTs in LLVM IR (with fewer_names)
6 participants