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

Add FileCheck annotations to mir-opt/copy-prop #135099

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

Shunpoco
Copy link
Contributor

@Shunpoco Shunpoco commented Jan 4, 2025

This resolves a part of #116971 .

This PR adds FileCheck annotations to test files under mir-opt/copy-prop.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented Jan 4, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@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 Jan 4, 2025
dummy(x);
x = 5;
}

// EMIT_MIR copy_propagation_arg.baz.CopyProp.diff
fn baz(mut x: i32) -> i32 {
// CHECK-LABEL: fn baz(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm wondering if we don't need this function for CopyProp.
I guess this test file originally from dest-prop, and in dest-prop the self-assignment is eliminated. But in copy-prop, it is not eliminated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. Do you mind fixing the comment and adding a CHECK: [[x]] = copy [[x]];?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and adding a CHECK: [[x]] = copy [[x]];?

There is no self-copy instruction in the mir file, but it has _2 = copy _1 and _0 = copy _1 (I already added).
Do you mean that I should add CHECK: _2 = copy [[x]];?

Copy link
Contributor Author

@Shunpoco Shunpoco Jan 8, 2025

Choose a reason for hiding this comment

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

I modified it in 7a64137. Please check if the change matches with your thought 🙏

@@ -9,6 +8,9 @@ use core::intrinsics::mir::*;
// EMIT_MIR partial_init.main.CopyProp.diff
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
pub fn main() {
// CHECK-LABEL: fn main(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this FileCheck annotations, but actually this test case doesn't need them since it checks if rustc compiles the function with CopyProp.
I'd like to confirm that we should keep skip-filecheck, or go forward with those annotations.

Copy link
Contributor

Choose a reason for hiding this comment

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

The annotations you put are enough.

@Shunpoco Shunpoco marked this pull request as ready for review January 4, 2025 13:16
@Shunpoco
Copy link
Contributor Author

Shunpoco commented Jan 4, 2025

r? @cjgillot

@rustbot rustbot assigned cjgillot and unassigned Mark-Simulacrum Jan 4, 2025
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the great work. A few nits.

// CHECK-NOT: StorageLive(_1);
// CHECK-NOT: _1 = dummy(const 5_u8)
// CHECK-NOT: _0 = copy _1;
// CHECK-NOT: StorageDead(_1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind adding a CHECK: _0 = dummy(const 5_u8)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 1aeeebc

let y = dummy(5); // this should get NRVO
y
}

// EMIT_MIR calls.multiple_edges.CopyProp.diff
#[custom_mir(dialect = "runtime", phase = "initial")]
fn multiple_edges(t: bool) -> u8 {
// CHECK-LABEL: fn multiple_edges(
// CHECK: bb2: {
// CHECK: _0 = copy _2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind adding a CHECK: _2 = dummy(const 13_u8)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 1aeeebc

dummy(x);
x = 5;
}

// EMIT_MIR copy_propagation_arg.baz.CopyProp.diff
fn baz(mut x: i32) -> i32 {
// CHECK-LABEL: fn baz(
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed. Do you mind fixing the comment and adding a CHECK: [[x]] = copy [[x]];?

@@ -8,6 +7,16 @@ fn val() -> i32 {

// EMIT_MIR cycle.main.CopyProp.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug z => _2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add the debug info for x and y too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 30a656a

@@ -1,4 +1,3 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// This is a copy of the `dead_stores_79191` test, except that we turn on DSE. This demonstrates
// that that pass enables this one to do more optimizations.
Copy link
Contributor

Choose a reason for hiding this comment

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

The compile-flags are not up-to-date. They should specify DeadStoreElimination-initial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified in 0d6fa54

// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
//@ test-mir-pass: CopyProp

// EMIT_MIR issue_107511.main.CopyProp.diff
fn main() {
// CHECK-LABEL: fn main(
// CHECK-NOT: StorageLive(_16);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add debuginfo for _16, so we understand what happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 430d888

// CHECK: bb0: {
// CHECK-NOT: _2 = copy [[a]];
// CHECK-NOT: _3 = move (_2.0: u8);
// CHECK: _3 = copy ([[a]].0: u8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add the CHECK: _0 = opaque(copy [[a]]) and CHECK: _0 = opaque(move _3)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 6eab7c7

@@ -9,6 +8,9 @@ use core::intrinsics::mir::*;
// EMIT_MIR partial_init.main.CopyProp.diff
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
pub fn main() {
// CHECK-LABEL: fn main(
Copy link
Contributor

Choose a reason for hiding this comment

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

The annotations you put are enough.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
…-initial

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants