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

Improvements to dataflow const-prop #115612

Merged
merged 9 commits into from
Sep 8, 2023
Merged

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Sep 6, 2023

Partially cherry-picked from #110719

r? @oli-obk
cc @jachris

@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 Sep 6, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 6, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@cjgillot cjgillot added the A-mir-opt Area: MIR optimizations label Sep 6, 2023
Comment on lines 2319 to 2321
pub fn try_to_scalar_int(self) -> Option<ScalarInt> {
Some(self.try_to_scalar()?.assert_int())
self.try_to_scalar()?.try_to_int().ok()
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we did this on purpose, but since it's undocumented and a footgun 👍

let old = self.projections.insert((place, TrackElem::Discriminant), discr);
assert!(old.is_none());

// Allocate a value slot if it doesn't have one.
Copy link
Contributor

Choose a reason for hiding this comment

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

this comment is outdated. It's now "since it doesn't have one"

Comment on lines +218 to +222
match self.eval_operand(operand, state) {
FlatSet::Elem(op) => self.wrap_immediate(*op),
FlatSet::Bottom => FlatSet::Bottom,
FlatSet::Top => FlatSet::Top,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

FlatSet should probably have a map method

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use case is so rare, I'm not sure it's worth it.

Copy link
Contributor

Choose a reason for hiding this comment

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

not important, just saw 3 occurrences of this code snippet ^^

Comment on lines 216 to 225
if let ty::Array(_, len) = place_ty.ty.kind() {
ConstantKind::Ty(*len)
.eval(self.tcx, self.param_env)
.try_to_scalar_int()
.map_or(FlatSet::Top, FlatSet::Elem)
} else if let [ProjectionElem::Deref] = place.projection[..] {
state.get_len(place.local.into(), self.map())
} else {
FlatSet::Top
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There's another option. If the slice is from a constant, we could even read the length from the constant, without it needing to be derived from an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, we'd still have Len(*_local) where _local holds the slice. For that case, I'd rather directly implement general assignments x = const where the RHS is not a scalar.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 7, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Sep 7, 2023

📌 Commit b7a925a 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 Sep 7, 2023
assert!(old.is_none());

// Allocate a value slot since it doesn't have one.
assert!( self.places[len].value_index.is_none() );
Copy link
Contributor

Choose a reason for hiding this comment

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

rustfmt skipped trailing spaces, but i can't repro this locally.

Copy link
Contributor

@klensy klensy Sep 7, 2023

Choose a reason for hiding this comment

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

Ah, let chains strikes again:

fn foo() {
    if let Some(ref_ty) = x && let ty::Slice(..) = y {
            assert!( self.places[len].value_index.is_none() );
    }
}

@bors
Copy link
Contributor

bors commented Sep 8, 2023

⌛ Testing commit b7a925a with merge b84d659...

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 8, 2023
Improvements to dataflow const-prop

Partially cherry-picked from rust-lang#110719

r? `@oli-obk`
cc `@jachris`
@bors
Copy link
Contributor

bors commented Sep 8, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 8, 2023
@bors
Copy link
Contributor

bors commented Sep 8, 2023

👀 Test was successful, but fast-forwarding failed: 422 Update is not a fast forward

@lqd
Copy link
Member

lqd commented Sep 8, 2023

@bors retry

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b84d659): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

Max RSS (memory usage)

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

Cycles

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

Binary size

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

Bootstrap: 628.962s -> 628.303s (-0.10%)
Artifact size: 318.09 MiB -> 318.03 MiB (-0.02%)

@bors
Copy link
Contributor

bors commented Sep 8, 2023

⌛ Testing commit b7a925a with merge 3cd97ed...

@bors
Copy link
Contributor

bors commented Sep 8, 2023

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

@bors bors merged commit 3cd97ed into rust-lang:master Sep 8, 2023
12 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 8, 2023
@cjgillot cjgillot deleted the const-prop-int branch September 8, 2023 18:36
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3cd97ed): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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

Binary size

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

Bootstrap: 629.777s -> 629.933s (0.02%)
Artifact size: 318.21 MiB -> 318.10 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations merged-by-bors This PR was explicitly merged by bors. 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