Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 181 additions & 59 deletions compiler/rustc_mir_transform/src/dest_prop.rs

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions tests/codegen-llvm/scalar-pair-bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
pair
}

// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
// CHECK: define{{.*}}{ i1, i1 } @pair_and_or(i1 noundef zeroext %0, i1 noundef zeroext %1)
#[no_mangle]
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
// Make sure it can operate directly on the unpacked args
// (but it might not be using simple and/or instructions)
// CHECK-DAG: %_1.0
// CHECK-DAG: %_1.1
// CHECK: or i1 %0, %1
// CHECK: and i1 %0, %1
(a && b, a || b)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

fn remap_debuginfo_locals(_1: bool, _2: &bool) -> &bool {
- debug c => _3;
+ debug c => _2;
+ debug c => _0;
let mut _0: &bool;
let mut _3: &bool;
let mut _4: bool;
Expand All @@ -14,10 +14,10 @@
- _4 = copy _1;
- _3 = copy _2;
- switchInt(copy _4) -> [1: bb1, otherwise: bb2];
+ // DBG: _2 = &_1;
+ nop;
+ // DBG: _0 = &_1;
+ nop;
+ nop;
+ _0 = copy _2;
+ switchInt(copy _1) -> [1: bb1, otherwise: bb2];
}

Expand All @@ -29,7 +29,7 @@
- StorageDead(_4);
- _0 = copy _3;
+ nop;
+ _0 = copy _2;
+ nop;
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
let mut _3: u8;

bb0: {
StorageLive(_2);
- StorageLive(_3);
- _3 = copy _1;
- _2 = dummy(move _3) -> [return: bb1, unwind unreachable];
+ nop;
- StorageLive(_2);
+ nop;
+ _2 = dummy(move _1) -> [return: bb1, unwind unreachable];
StorageLive(_3);
_3 = copy _1;
- _2 = dummy(move _3) -> [return: bb1, unwind unreachable];
+ _1 = dummy(move _3) -> [return: bb1, unwind unreachable];
}

bb1: {
- StorageDead(_3);
StorageDead(_3);
- _1 = move _2;
- StorageDead(_2);
+ nop;
+ nop;
_1 = move _2;
StorageDead(_2);
_0 = const ();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
let mut _3: u8;

bb0: {
StorageLive(_2);
- StorageLive(_3);
- _3 = copy _1;
- _2 = dummy(move _3) -> [return: bb1, unwind continue];
+ nop;
- StorageLive(_2);
+ nop;
+ _2 = dummy(move _1) -> [return: bb1, unwind continue];
StorageLive(_3);
_3 = copy _1;
- _2 = dummy(move _3) -> [return: bb1, unwind continue];
+ _1 = dummy(move _3) -> [return: bb1, unwind continue];
}

bb1: {
- StorageDead(_3);
StorageDead(_3);
- _1 = move _2;
- StorageDead(_2);
+ nop;
+ nop;
_1 = move _2;
StorageDead(_2);
_0 = const ();
return;
}
Expand Down
5 changes: 3 additions & 2 deletions tests/mir-opt/dest-prop/copy_propagation_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ fn dummy(x: u8) -> u8 {
fn foo(mut x: u8) {
// CHECK-LABEL: fn foo(
// CHECK: debug x => [[x:_.*]];
// CHECK: dummy(move [[x]])
// CHECK: [[x]] = move {{_.*}};
// CHECK: [[tmp:_.*]] = copy [[x]];
// CHECK: [[x]] = dummy(move [[tmp]])

// calling `dummy` to make a use of `x` that copyprop cannot eliminate
x = dummy(x); // this will assign a local to `x`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
let _5: ();
let mut _6: i32;
scope 1 {
debug x => _1;
- debug x => _1;
+ debug x => _4;
let _2: i32;
scope 2 {
- debug y => _2;
+ debug y => _1;
+ debug y => _4;
let _3: i32;
scope 3 {
- debug z => _3;
+ debug z => _1;
+ debug z => _4;
}
}
}

bb0: {
- StorageLive(_1);
- _1 = val() -> [return: bb1, unwind unreachable];
+ nop;
_1 = val() -> [return: bb1, unwind unreachable];
+ _4 = val() -> [return: bb1, unwind unreachable];
}

bb1: {
Expand All @@ -50,7 +52,7 @@
- _5 = std::mem::drop::<i32>(move _6) -> [return: bb2, unwind unreachable];
+ nop;
+ nop;
+ _5 = std::mem::drop::<i32>(move _1) -> [return: bb2, unwind unreachable];
+ _5 = std::mem::drop::<i32>(move _4) -> [return: bb2, unwind unreachable];
}

bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
let _5: ();
let mut _6: i32;
scope 1 {
debug x => _1;
- debug x => _1;
+ debug x => _4;
let _2: i32;
scope 2 {
- debug y => _2;
+ debug y => _1;
+ debug y => _4;
let _3: i32;
scope 3 {
- debug z => _3;
+ debug z => _1;
+ debug z => _4;
}
}
}

bb0: {
- StorageLive(_1);
- _1 = val() -> [return: bb1, unwind continue];
+ nop;
_1 = val() -> [return: bb1, unwind continue];
+ _4 = val() -> [return: bb1, unwind continue];
}

bb1: {
Expand All @@ -50,7 +52,7 @@
- _5 = std::mem::drop::<i32>(move _6) -> [return: bb2, unwind continue];
+ nop;
+ nop;
+ _5 = std::mem::drop::<i32>(move _1) -> [return: bb2, unwind continue];
+ _5 = std::mem::drop::<i32>(move _4) -> [return: bb2, unwind continue];
}

bb2: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
}

bb0: {
nop;
StorageLive(_2);
_2 = copy _1;
_1 = const 5_usize;
nop;
_1 = copy _2;
nop;
_1 = move _2;
nop;
nop;
nop;
Expand All @@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {

bb1: {
nop;
nop;
StorageDead(_2);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
}

bb0: {
nop;
StorageLive(_2);
_2 = copy _1;
_1 = const 5_usize;
nop;
_1 = copy _2;
nop;
_1 = move _2;
nop;
nop;
nop;
Expand All @@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {

bb1: {
nop;
nop;
StorageDead(_2);
return;
}
}
2 changes: 1 addition & 1 deletion tests/mir-opt/dest-prop/dead_stores_79191.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn f(mut a: usize) -> usize {
// CHECK: debug b => [[b:_.*]];
// CHECK: [[b]] = copy [[a]];
// CHECK: [[a]] = const 5_usize;
// CHECK: [[a]] = move [[b]];
// CHECK: [[a]] = copy [[b]];
// CHECK: id::<usize>(move [[a]])
let b = a;
a = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
}

bb0: {
nop;
StorageLive(_2);
_2 = copy _1;
_1 = const 5_usize;
nop;
_1 = copy _2;
nop;
_1 = move _2;
nop;
nop;
nop;
Expand All @@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {

bb1: {
nop;
nop;
StorageDead(_2);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ fn f(_1: usize) -> usize {
}

bb0: {
nop;
StorageLive(_2);
_2 = copy _1;
_1 = const 5_usize;
nop;
_1 = copy _2;
nop;
_1 = move _2;
nop;
nop;
nop;
Expand All @@ -25,7 +25,7 @@ fn f(_1: usize) -> usize {

bb1: {
nop;
nop;
StorageDead(_2);
return;
}
}
2 changes: 1 addition & 1 deletion tests/mir-opt/dest-prop/dead_stores_better.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn f(mut a: usize) -> usize {
// CHECK: debug b => [[b:_.*]];
// CHECK: [[b]] = copy [[a]];
// CHECK: [[a]] = const 5_usize;
// CHECK: [[a]] = move [[b]];
// CHECK: [[a]] = copy [[b]];
// CHECK: id::<usize>(move [[a]])
let b = a;
a = 5;
Expand Down
Loading
Loading