-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
base: master
Are you sure you want to change the base?
Changes from all commits
1b5a744
e6dcb25
78a143f
ab21ba3
4057797
77d5711
f53476b
2d04a63
d0365d3
334d501
d3176d5
ef42830
4627ea1
381466c
1aeeebc
30a656a
0d6fa54
430d888
6eab7c7
7a64137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// skip-filecheck | ||
// Check that CopyProp does propagate return values of call terminators. | ||
//@ test-mir-pass: CopyProp | ||
//@ needs-unwind | ||
|
@@ -13,13 +12,25 @@ fn dummy(x: u8) -> u8 { | |
|
||
// EMIT_MIR calls.nrvo.CopyProp.diff | ||
fn nrvo() -> u8 { | ||
// CHECK-LABEL: fn nrvo( | ||
// CHECK: debug y => _0; | ||
// CHECK-NOT: StorageLive(_1); | ||
// CHECK-NOT: _1 = dummy(const 5_u8) | ||
// CHECK: _0 = dummy(const 5_u8) | ||
// CHECK-NOT: _0 = copy _1; | ||
// CHECK-NOT: StorageDead(_1); | ||
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: bb1: { | ||
// CHECK: _2 = dummy(const 13_u8) | ||
// CHECK: bb2: { | ||
// CHECK: _0 = copy _2; | ||
mir! { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 1aeeebc |
||
let x: u8; | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// skip-filecheck | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
// Check that CopyProp does not propagate an assignment to a function argument | ||
// (doing so can break usages of the original argument value) | ||
|
@@ -9,25 +8,46 @@ fn dummy(x: u8) -> u8 { | |
|
||
// EMIT_MIR copy_propagation_arg.foo.CopyProp.diff | ||
fn foo(mut x: u8) { | ||
// CHECK-LABEL: fn foo( | ||
// CHECK: debug x => [[x:_.*]]; | ||
// CHECK: [[three:_.*]] = copy [[x]]; | ||
// CHECK: [[two:_.*]] = dummy(move [[three]]) | ||
// CHECK: [[x]] = move [[two]]; | ||
// calling `dummy` to make a use of `x` that copyprop cannot eliminate | ||
x = dummy(x); // this will assign a local to `x` | ||
} | ||
|
||
// EMIT_MIR copy_propagation_arg.bar.CopyProp.diff | ||
fn bar(mut x: u8) { | ||
// CHECK-LABEL: fn bar( | ||
// CHECK: debug x => [[x:_.*]]; | ||
// CHECK: [[three:_.*]] = copy [[x]]; | ||
// CHECK: dummy(move [[three]]) | ||
// CHECK: [[x]] = const 5_u8; | ||
dummy(x); | ||
x = 5; | ||
} | ||
|
||
// EMIT_MIR copy_propagation_arg.baz.CopyProp.diff | ||
fn baz(mut x: i32) -> i32 { | ||
// self-assignment to a function argument should be eliminated | ||
// CHECK-LABEL: fn baz( | ||
// CHECK: debug x => [[x:_.*]]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we don't need this function for CopyProp. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Do you mind fixing the comment and adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There is no self-copy instruction in the mir file, but it has There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🙏 |
||
// CHECK: [[x2:_.*]] = copy [[x]]; | ||
// CHECK: [[x]] = move [[x2]]; | ||
// CHECK: _0 = copy [[x]]; | ||
// In the original case for DestProp, the self-assignment to a function argument is eliminated, | ||
// but in CopyProp it is not eliminated. | ||
x = x; | ||
x | ||
} | ||
|
||
// EMIT_MIR copy_propagation_arg.arg_src.CopyProp.diff | ||
fn arg_src(mut x: i32) -> i32 { | ||
// CHECK-LABEL: fn arg_src( | ||
// CHECK: debug x => [[x:_.*]]; | ||
// CHECK: debug y => [[y:_.*]]; | ||
// CHECK: [[y]] = copy [[x]]; | ||
// CHECK: [[x]] = const 123_i32; | ||
let y = x; | ||
x = 123; // Don't propagate this assignment to `y` | ||
y | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
// 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. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compile-flags are not up-to-date. They should specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Modified in 0d6fa54 |
||
//@ test-mir-pass: CopyProp | ||
//@ compile-flags: -Zmir-enable-passes=+DeadStoreElimination | ||
//@ compile-flags: -Zmir-enable-passes=+DeadStoreElimination-initial | ||
|
||
fn id<T>(x: T) -> T { | ||
x | ||
} | ||
|
||
// EMIT_MIR dead_stores_better.f.CopyProp.after.mir | ||
pub fn f(mut a: usize) -> usize { | ||
// CHECK-LABEL: fn f( | ||
// CHECK: debug a => [[a:_.*]]; | ||
// CHECK: debug b => [[b:_.*]]; | ||
// CHECK: [[b]] = copy [[a]]; | ||
// CHECK: [[a]] = const 5_usize; | ||
// CHECK: [[a]] = copy [[b]]; | ||
// CHECK: [[c:_.*]] = copy [[a]] | ||
// CHECK: id::<usize>(move [[c]]) | ||
let b = a; | ||
a = 5; | ||
a = b; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// skip-filecheck | ||
//@ test-mir-pass: CopyProp | ||
// Verify that we do not ICE on partial initializations. | ||
|
||
|
@@ -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( | ||
// CHECK: let mut [[x:_.*]]: (isize,); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The annotations you put are enough. |
||
// CHECK: ([[x]].0: isize) = const 1_isize; | ||
mir! ( | ||
let x: (isize, ); | ||
{ | ||
|
There was a problem hiding this comment.
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)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 1aeeebc