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

Simplify the canonical clone method and the copy-like forms to copy #128299

Merged
merged 2 commits into from
Sep 14, 2024

Conversation

DianQK
Copy link
Member

@DianQK DianQK commented Jul 28, 2024

Fixes #128081.

The optimized clone method ends up as the following MIR:

_2 = copy ((*_1).0: i32);
_3 = copy ((*_1).1: u64);
_4 = copy ((*_1).2: [i8; 3]);
_0 = Foo { a: move _2, b: move _3, c: move _4 };

We can transform this to:

_0 = copy (*_1);

r? @cjgillot

@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. S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Jul 28, 2024
@rust-log-analyzer

This comment has been minimized.

@DianQK
Copy link
Member Author

DianQK commented Jul 28, 2024

@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 Jul 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 28, 2024
Simplify the canonical clone method and the copy-like forms to copy

Fixes rust-lang#128081. Currently being blocked by rust-lang#128265.

`@rustbot` label +S-blocked

r? `@saethlin`
@bors
Copy link
Contributor

bors commented Jul 28, 2024

⌛ Trying commit 31a1608 with merge e4c8ee7...

@bors
Copy link
Contributor

bors commented Jul 28, 2024

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e4c8ee7): 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.9% [0.3%, 2.7%] 26
Regressions ❌
(secondary)
1.4% [0.1%, 4.0%] 7
Improvements ✅
(primary)
-0.7% [-1.8%, -0.2%] 7
Improvements ✅
(secondary)
-0.6% [-1.1%, -0.3%] 4
All ❌✅ (primary) 0.6% [-1.8%, 2.7%] 33

Max RSS (memory usage)

Results (primary -0.9%, secondary -2.9%)

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.8% [2.6%, 6.8%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.8% [-4.9%, -0.4%] 24
Improvements ✅
(secondary)
-2.9% [-3.7%, -2.2%] 2
All ❌✅ (primary) -0.9% [-4.9%, 6.8%] 28

Cycles

Results (primary 1.4%, secondary -0.9%)

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% [1.0%, 2.3%] 6
Regressions ❌
(secondary)
2.7% [2.2%, 3.0%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-4.5%, -1.3%] 11
All ❌✅ (primary) 1.4% [1.0%, 2.3%] 6

Binary size

Results (primary -0.1%, secondary -0.6%)

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.2% [0.0%, 0.6%] 41
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 3
Improvements ✅
(primary)
-0.3% [-1.1%, -0.0%] 45
Improvements ✅
(secondary)
-0.7% [-1.7%, -0.0%] 19
All ❌✅ (primary) -0.1% [-1.1%, 0.6%] 86

Bootstrap: 772.73s -> 772.725s (-0.00%)
Artifact size: 331.60 MiB -> 331.61 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jul 28, 2024
@DianQK
Copy link
Member Author

DianQK commented Jul 29, 2024

@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 Jul 29, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 29, 2024
Simplify the canonical clone method and the copy-like forms to copy

Fixes rust-lang#128081. Currently being blocked by rust-lang#128265.

`@rustbot` label +S-blocked

r? `@saethlin`
@bors
Copy link
Contributor

bors commented Jul 29, 2024

⌛ Trying commit a7d48fc with merge 39db211...

@bors
Copy link
Contributor

bors commented Jul 29, 2024

☀️ Try build successful - checks-actions
Build commit: 39db211 (39db211ca6455f46c20f96c349f1e12734c085ba)

@rust-timer

This comment has been minimized.

@DianQK
Copy link
Member Author

DianQK commented Jul 29, 2024

@rustbot label -S-blocked

@rustbot rustbot removed the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Jul 29, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (39db211): 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.8% [0.3%, 1.5%] 21
Regressions ❌
(secondary)
2.6% [0.4%, 5.4%] 4
Improvements ✅
(primary)
-1.9% [-1.9%, -1.9%] 1
Improvements ✅
(secondary)
-1.4% [-1.4%, -1.4%] 1
All ❌✅ (primary) 0.7% [-1.9%, 1.5%] 22

Max RSS (memory usage)

Results (primary 2.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.

mean range count
Regressions ❌
(primary)
3.7% [1.9%, 6.9%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.1% [-5.1%, -5.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.2% [-5.1%, 6.9%] 6

Cycles

Results (primary 1.2%, secondary 3.3%)

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.2% [0.7%, 1.7%] 12
Regressions ❌
(secondary)
3.3% [2.3%, 3.9%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.2% [0.7%, 1.7%] 12

Binary size

Results (primary -0.0%, secondary -0.3%)

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.2%] 7
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.5%, -0.3%] 2
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 3
All ❌✅ (primary) -0.0% [-0.5%, 0.2%] 9

Bootstrap: 770.008s -> 770.86s (0.11%)
Artifact size: 331.82 MiB -> 331.70 MiB (-0.04%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 30, 2024
@cjgillot
Copy link
Contributor

I wonder if implementing this in GVN pass would be simpler. It already tracks value assignments.

@DianQK
Copy link
Member Author

DianQK commented Jul 30, 2024

I wonder if implementing this in GVN pass would be simpler. It already tracks value assignments.

It's possible. I'm considering GVN or backward traversal.

@bors
Copy link
Contributor

bors commented Sep 14, 2024

📌 Commit 25d434b has been approved by cjgillot

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 14, 2024
@bors
Copy link
Contributor

bors commented Sep 14, 2024

⌛ Testing commit 25d434b with merge e7386b3...

@bors
Copy link
Contributor

bors commented Sep 14, 2024

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing e7386b3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 14, 2024
@bors bors merged commit e7386b3 into rust-lang:master Sep 14, 2024
7 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Sep 14, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e7386b3): 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)
0.4% [0.2%, 0.8%] 6
Regressions ❌
(secondary)
0.4% [0.2%, 2.1%] 16
Improvements ✅
(primary)
-0.8% [-1.7%, -0.3%] 12
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-1.7%, 0.8%] 18

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.

mean range count
Regressions ❌
(primary)
5.6% [3.5%, 7.6%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-4.4% [-7.7%, -3.0%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.1% [-7.7%, 7.6%] 6

Cycles

Results (primary -0.6%)

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.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-1.8%, -1.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-1.8%, 1.2%] 3

Binary size

Results (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.

mean range count
Regressions ❌
(primary)
0.2% [0.0%, 0.4%] 11
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 16
Improvements ✅
(primary)
-0.2% [-1.3%, -0.0%] 29
Improvements ✅
(secondary)
-0.5% [-1.2%, -0.1%] 15
All ❌✅ (primary) -0.1% [-1.3%, 0.4%] 40

Bootstrap: 757.228s -> 759.427s (0.29%)
Artifact size: 341.16 MiB -> 341.17 MiB (0.00%)

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2024
Merge these copy statements that simplified the canonical enum clone method by GVN

This is blocked by rust-lang#128299.
@DianQK DianQK deleted the clone-copy branch September 15, 2024 03:57
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
mir-opt: Merge all branch BBs into a single copy statement

rust-lang#128299 simplified
```rust
match a {
    Foo::A(x) => Foo::A(*x),
    Foo::B => Foo::B
}
```
to
```rust
match a {
    Foo::A(x) => a, // copy a
    Foo::B => Foo::B
}
```

The switch branch can be simplified into a single copy statement. This PR implements a relatively general simplification.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 6, 2024
mir-opt: Merge all branch BBs into a single copy statement

rust-lang#128299 simplified
```rust
match a {
    Foo::A(x) => Foo::A(*x),
    Foo::B => Foo::B
}
```
to
```rust
match a {
    Foo::A(x) => a, // copy a
    Foo::B => Foo::B
}
```

The switch branch can be simplified into a single copy statement. This PR implements a relatively general simplification.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 30, 2024
Mark the `simplify_aggregate_to_copy` mir-opt added in
<rust-lang#128299>.

This **partially** reverts commit
e7386b3,
reversing changes made to 02b1be1. The
implementation is just marked as unsound, but the test changes are
reverted.
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 30, 2024
Mark the `simplify_aggregate_to_copy` mir-opt added in
<rust-lang#128299>.

This **partially** reverts commit
e7386b3,
reversing changes made to 02b1be1. The
implementation is just marked as unsound, but the test changes are
reverted.
@jieyouxu
Copy link
Member

jieyouxu commented Oct 30, 2024

For easier git archaeology:

jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 30, 2024
…to_copy, r=cjgillot

Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in rust-lang#128299 as unsound as it seems to miscompile the MCVE reported in rust-lang#132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. The test changes are **fully** reverted.

cc `@DianQK` `@cjgillot` (PR author and reviewer of rust-lang#128299)
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 31, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Oct 31, 2024
Co-authored-by: DianQK <dianqk@dianqk.net>
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
…to_copy, r=cjgillot,DianQK

Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in rust-lang#128299 as unsound as it seems to miscompile the MCVE reported in rust-lang#132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. The test changes are **fully** reverted.

cc `@DianQK` `@cjgillot` (PR author and reviewer of rust-lang#128299)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2024
…e_to_copy, r=cjgillot,DianQK

Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in rust-lang#128299 as unsound as it seems to miscompile the MCVE reported in rust-lang#132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. The test changes are **fully** reverted.

cc `@DianQK` `@cjgillot` (PR author and reviewer of rust-lang#128299)
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 31, 2024
…to_copy, r=cjgillot,DianQK

Mark `simplify_aggregate_to_copy` mir-opt as unsound

Mark the `simplify_aggregate_to_copy` mir-opt added in rust-lang#128299 as unsound as it seems to miscompile the MCVE reported in rust-lang#132353. The mir-opt can be re-enabled once this case is fixed.

```rs
fn pop_min(mut score2head: Vec<Option<usize>>) -> Option<usize> {
    loop {
        if let Some(col) = score2head[0] {
            score2head[0] = None;
            return Some(col);
        }
    }
}

fn main() {
    let min = pop_min(vec![Some(1)]);
    println!("min: {:?}", min);
    // panic happens here on beta in release mode
    // but not in debug mode
    min.unwrap();
}
```

This MCVE is included as a `run-pass` ui regression test in the first commit. I built the ui test with a nightly manually, and can reproduce the behavioral difference with `-C opt-level=0` and `-C opt-level=1`. Locally, this ui test will fail unless it was run on a compiler built with the second commit marking the mir-opt as unsound thus disabling it by default.

This PR **partially reverts** commit e7386b3, reversing changes made to 02b1be1. The mir-opt implementation is just marked as unsound but **not** reverted to make reland reviews easier. Test changes are **reverted if they were not pure additions**. Tests added by the original PR received `-Z unsound-mir-opts` compile-flags.

cc `@DianQK` `@cjgillot` (PR author and reviewer of rust-lang#128299)
cuviper pushed a commit to cuviper/rust that referenced this pull request Nov 1, 2024
Co-authored-by: DianQK <dianqk@dianqk.net>
(cherry picked from commit cfb4c05)
icmccorm pushed a commit to borrow-sanitizer/rust that referenced this pull request Nov 2, 2024
Co-authored-by: DianQK <dianqk@dianqk.net>
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.

Bad codegen for non-copy-derived struct with all Copy derived fields
10 participants