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

Strengthen state tracking in const-prop #108872

Merged
merged 13 commits into from
Mar 13, 2023
Merged

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Mar 7, 2023

Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization.

Behaviour changes:

  • const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen.
  • we remove the OnlyPropagateInto mode. It was only used for function arguments, which are better modeled by a write before entry.
  • the tracking of assignments and discriminants make clearer that we do nothing in NoPropagation mode or on indirect places.

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2023

r? @davidtwco

(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 Mar 7, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2023

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot
Copy link
Collaborator

rustbot commented Mar 7, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

source_info.span,
));
*rval =
Rvalue::Use(self.operand_from_scalar(scalar, value.layout.ty, DUMMY_SP));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operand_from_scalar could just stop taking a span alltogether

@oli-obk
Copy link
Contributor

oli-obk commented Mar 8, 2023

r=me with operand_from_scalar havings its span arg removed

@davidtwco davidtwco assigned oli-obk and unassigned davidtwco Mar 8, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Mar 8, 2023

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Mar 8, 2023

📌 Commit 8179b2e has been approved by oli-obk

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 Mar 8, 2023
@bors
Copy link
Contributor

bors commented Mar 12, 2023

⌛ Testing commit 8179b2e with merge b05bb29...

@bors
Copy link
Contributor

bors commented Mar 13, 2023

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing b05bb29 to master...

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b05bb29): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.4% [0.6%, 6.3%] 30
Regressions ❌
(secondary)
41.6% [0.3%, 139.3%] 12
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.4% [-1.9%, -1.0%] 2
All ❌✅ (primary) 2.4% [0.6%, 6.3%] 30

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)
-2.2% [-2.2%, -2.2%] 1
Improvements ✅
(secondary)
-2.2% [-2.6%, -1.5%] 4
All ❌✅ (primary) -2.2% [-2.2%, -2.2%] 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)
1.4% [0.9%, 1.6%] 5
Regressions ❌
(secondary)
21.5% [3.9%, 45.4%] 8
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [0.9%, 1.6%] 5

@rustbot rustbot added the perf-regression Performance regression. label Mar 13, 2023
Comment on lines +968 to +970
for (local, &mode) in can_const_prop.iter_enumerated() {
match mode {
ConstPropMode::FullConstProp => {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like the regression is from this loop? At least that's what my profiler indicates. It looks like basically all the cycles in ConstProp are driving this iterator and hitting this first case:

 16.79 │ d0:┌─→inc    %rdi
       │    │<core::slice::iter::Iter<rustc_mir_transform::const_prop::ConstPropMode> as core::iter::traits::iterator::Iterator>::next:
 16.05 │    │  add    $0x48,%rdx
 16.52 │    │  cmp    %rdi,%rax
       │    │↓ je     12e
       │    │<rustc_middle::mir::Local>::from_usize: 
       │    │} 
       │    │
       │    │///////////////////////////////////////////////////////////////////////////
       │    │// Variables and temps 
       │    │ 
       │    │rustc_index::newtype_index! {
 25.17 │ dc:│  cmp    %r8,%rdi
       │    │↓ je     1b7
       │    │<rustc_mir_transform::const_prop::ConstPropagator as rustc_middle::mir::visit::MutVisitor>::visit_basic_block_data: 
       │    │match mode {
 25.18 │    ├──cmpb   $0x1,(%rcx,%rdi,1)
       │    └──jne    d0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not be working on this, but I suspect the problem centers around there being a lot of FullConstProp in here and we could be iterating over less elements somehow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the analysis. I'll handle it after hours.

@cjgillot cjgillot deleted the simp-const-prop branch March 13, 2023 20:24
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 22, 2023
Only clear written-to locals in ConstProp

This aims to revert the regression in rust-lang#108872

Clearing all locals at the end of each bb is very costly.
This PR goes back to the original implementation of recording which locals are modified.
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Mar 22, 2023
Only clear written-to locals in ConstProp

This aims to revert the regression in rust-lang/rust#108872

Clearing all locals at the end of each bb is very costly.
This PR goes back to the original implementation of recording which locals are modified.
flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 24, 2023
Strengthen state tracking in const-prop

Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization.

Behaviour changes:
- const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen.
- we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry.
- the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 20, 2024
Only clear written-to locals in ConstProp

This aims to revert the regression in rust-lang/rust#108872

Clearing all locals at the end of each bb is very costly.
This PR goes back to the original implementation of recording which locals are modified.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Only clear written-to locals in ConstProp

This aims to revert the regression in rust-lang/rust#108872

Clearing all locals at the end of each bb is very costly.
This PR goes back to the original implementation of recording which locals are modified.
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 Performance regression. 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.

7 participants