Skip to content

Commit 7894bbf

Browse files
committed
Add a pre-codegen MIR test for mem::swap
1 parent de0ebde commit 7894bbf

4 files changed

+374
-0
lines changed

tests/mir-opt/pre-codegen/mem_swap.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Z inline-mir-hint-threshold=300
2+
// only-64bit
3+
// ignore-debug
4+
5+
#![crate_type = "lib"]
6+
7+
// EMIT_MIR mem_swap.swap_primitive.PreCodegen.after.mir
8+
pub fn swap_primitive(a: &mut i32, b: &mut i32) {
9+
std::mem::swap(a, b);
10+
}
11+
12+
// EMIT_MIR mem_swap.swap_generic.PreCodegen.after.mir
13+
pub fn swap_generic<'a, T>(a: &mut T, b: &mut T) {
14+
std::mem::swap(a, b);
15+
}
16+
17+
// EMIT_MIR mem_swap.swap_big.PreCodegen.after.mir
18+
pub fn swap_big(a: &mut [String; 9], b: &mut [String; 9]) {
19+
std::mem::swap(a, b);
20+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// MIR for `swap_big` after PreCodegen
2+
3+
fn swap_big(_1: &mut [String; 9], _2: &mut [String; 9]) -> () {
4+
debug a => _1; // in scope 0 at $DIR/mem_swap.rs:+0:17: +0:18
5+
debug b => _2; // in scope 0 at $DIR/mem_swap.rs:+0:38: +0:39
6+
let mut _0: (); // return place in scope 0 at $DIR/mem_swap.rs:+0:59: +0:59
7+
let _3: (); // in scope 0 at $DIR/mem_swap.rs:+1:5: +1:25
8+
scope 1 (inlined std::mem::swap::<[String; 9]>) { // at $DIR/mem_swap.rs:19:5: 19:25
9+
debug x => _1; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
10+
debug y => _2; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
11+
let mut _4: *mut [std::string::String; 9]; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
12+
let mut _5: *mut [std::string::String; 9]; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
13+
scope 2 {
14+
}
15+
scope 3 (inlined std::mem::size_of::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
16+
}
17+
scope 4 (inlined align_of::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
18+
}
19+
scope 5 (inlined mem::swap_simple::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
20+
debug x => _1; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
21+
debug y => _2; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
22+
let mut _7: *const [std::string::String; 9]; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
23+
let mut _9: *const [std::string::String; 9]; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
24+
let mut _10: *mut [std::string::String; 9]; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
25+
let mut _11: *mut [std::string::String; 9]; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
26+
scope 6 {
27+
let _6: [std::string::String; 9]; // in scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
28+
scope 7 {
29+
debug a => _6; // in scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
30+
let _8: [std::string::String; 9]; // in scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
31+
scope 8 {
32+
debug b => _8; // in scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
33+
scope 15 (inlined std::ptr::write::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
34+
debug dst => _10; // in scope 15 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
35+
debug src => _8; // in scope 15 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
36+
let mut _14: *mut [std::string::String; 9]; // in scope 15 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
37+
scope 16 {
38+
scope 17 (inlined std::ptr::write::runtime::<[String; 9]>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
39+
debug dst => _14; // in scope 17 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
40+
}
41+
}
42+
}
43+
scope 18 (inlined std::ptr::write::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
44+
debug dst => _11; // in scope 18 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
45+
debug src => _6; // in scope 18 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
46+
let mut _15: *mut [std::string::String; 9]; // in scope 18 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
47+
scope 19 {
48+
scope 20 (inlined std::ptr::write::runtime::<[String; 9]>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
49+
debug dst => _15; // in scope 20 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
50+
}
51+
}
52+
}
53+
}
54+
scope 12 (inlined std::ptr::read::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
55+
debug src => _9; // in scope 12 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
56+
let mut _13: *const [std::string::String; 9]; // in scope 12 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
57+
scope 13 {
58+
scope 14 (inlined std::ptr::read::runtime::<[String; 9]>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
59+
debug src => _13; // in scope 14 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
60+
}
61+
}
62+
}
63+
}
64+
scope 9 (inlined std::ptr::read::<[String; 9]>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
65+
debug src => _7; // in scope 9 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
66+
let mut _12: *const [std::string::String; 9]; // in scope 9 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
67+
scope 10 {
68+
scope 11 (inlined std::ptr::read::runtime::<[String; 9]>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
69+
debug src => _12; // in scope 11 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
70+
}
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
bb0: {
78+
StorageLive(_4); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
79+
_4 = &raw mut (*_1); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
80+
StorageLive(_5); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
81+
_5 = &raw mut (*_2); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
82+
_3 = swap_nonoverlapping::<[String; 9]>(move _4, move _5, const 1_usize) -> bb1; // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
83+
// mir::Constant
84+
// + span: $SRC_DIR/core/src/mem/mod.rs:LL:COL
85+
// + literal: Const { ty: unsafe fn(*mut [String; 9], *mut [String; 9], usize) {swap_nonoverlapping::<[String; 9]>}, val: Value(<ZST>) }
86+
}
87+
88+
bb1: {
89+
StorageDead(_5); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
90+
StorageDead(_4); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
91+
return; // scope 0 at $DIR/mem_swap.rs:+2:2: +2:2
92+
}
93+
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// MIR for `swap_generic` after PreCodegen
2+
3+
fn swap_generic(_1: &mut T, _2: &mut T) -> () {
4+
debug a => _1; // in scope 0 at $DIR/mem_swap.rs:+0:28: +0:29
5+
debug b => _2; // in scope 0 at $DIR/mem_swap.rs:+0:39: +0:40
6+
let mut _0: (); // return place in scope 0 at $DIR/mem_swap.rs:+0:50: +0:50
7+
let _3: (); // in scope 0 at $DIR/mem_swap.rs:+1:5: +1:25
8+
scope 1 (inlined std::mem::swap::<T>) { // at $DIR/mem_swap.rs:14:5: 14:25
9+
debug x => _1; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
10+
debug y => _2; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
11+
let mut _4: bool; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
12+
let mut _5: usize; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
13+
let mut _6: usize; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
14+
let mut _7: usize; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
15+
let mut _8: bool; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
16+
let mut _9: *mut T; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
17+
let mut _10: *mut T; // in scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
18+
scope 2 {
19+
}
20+
scope 3 (inlined std::mem::size_of::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
21+
}
22+
scope 4 (inlined align_of::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
23+
}
24+
scope 5 (inlined mem::swap_simple::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
25+
debug x => _1; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
26+
debug y => _2; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
27+
let mut _12: *const T; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
28+
let mut _14: *const T; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
29+
let mut _15: *mut T; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
30+
let mut _16: *mut T; // in scope 5 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
31+
scope 6 {
32+
let _11: T; // in scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
33+
scope 7 {
34+
debug a => _11; // in scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
35+
let _13: T; // in scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
36+
scope 8 {
37+
debug b => _13; // in scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
38+
scope 15 (inlined std::ptr::write::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
39+
debug dst => _15; // in scope 15 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
40+
debug src => _13; // in scope 15 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
41+
let mut _19: *mut T; // in scope 15 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
42+
scope 16 {
43+
scope 17 (inlined std::ptr::write::runtime::<T>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
44+
debug dst => _19; // in scope 17 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
45+
}
46+
}
47+
}
48+
scope 18 (inlined std::ptr::write::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
49+
debug dst => _16; // in scope 18 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
50+
debug src => _11; // in scope 18 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
51+
let mut _20: *mut T; // in scope 18 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
52+
scope 19 {
53+
scope 20 (inlined std::ptr::write::runtime::<T>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
54+
debug dst => _20; // in scope 20 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
55+
}
56+
}
57+
}
58+
}
59+
scope 12 (inlined std::ptr::read::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
60+
debug src => _14; // in scope 12 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
61+
let mut _18: *const T; // in scope 12 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
62+
scope 13 {
63+
scope 14 (inlined std::ptr::read::runtime::<T>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
64+
debug src => _18; // in scope 14 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
65+
}
66+
}
67+
}
68+
}
69+
scope 9 (inlined std::ptr::read::<T>) { // at $SRC_DIR/core/src/mem/mod.rs:LL:COL
70+
debug src => _12; // in scope 9 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
71+
let mut _17: *const T; // in scope 9 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
72+
scope 10 {
73+
scope 11 (inlined std::ptr::read::runtime::<T>) { // at $SRC_DIR/core/src/intrinsics.rs:LL:COL
74+
debug src => _17; // in scope 11 at $SRC_DIR/core/src/intrinsics.rs:LL:COL
75+
}
76+
}
77+
}
78+
}
79+
}
80+
}
81+
82+
bb0: {
83+
StorageLive(_4); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
84+
StorageLive(_5); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
85+
StorageLive(_6); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
86+
_6 = SizeOf(T); // scope 3 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
87+
StorageLive(_7); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
88+
_7 = AlignOf(T); // scope 4 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
89+
_8 = Eq(_7, const 0_usize); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
90+
assert(!move _8, "attempt to divide `{}` by zero", _6) -> bb2; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
91+
}
92+
93+
bb1: {
94+
return; // scope 0 at $DIR/mem_swap.rs:+2:2: +2:2
95+
}
96+
97+
bb2: {
98+
_5 = Div(move _6, move _7); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
99+
StorageDead(_7); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
100+
StorageDead(_6); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
101+
_4 = Gt(move _5, const 4_usize); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
102+
StorageDead(_5); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
103+
switchInt(move _4) -> [0: bb5, otherwise: bb3]; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
104+
}
105+
106+
bb3: {
107+
StorageLive(_9); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
108+
_9 = &raw mut (*_1); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
109+
StorageLive(_10); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
110+
_10 = &raw mut (*_2); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
111+
_3 = swap_nonoverlapping::<T>(move _9, move _10, const 1_usize) -> bb4; // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
112+
// mir::Constant
113+
// + span: $SRC_DIR/core/src/mem/mod.rs:LL:COL
114+
// + literal: Const { ty: unsafe fn(*mut T, *mut T, usize) {swap_nonoverlapping::<T>}, val: Value(<ZST>) }
115+
}
116+
117+
bb4: {
118+
StorageDead(_10); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
119+
StorageDead(_9); // scope 2 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
120+
StorageDead(_4); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
121+
goto -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
122+
}
123+
124+
bb5: {
125+
StorageDead(_4); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
126+
StorageLive(_11); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
127+
StorageLive(_13); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
128+
StorageLive(_12); // scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
129+
_12 = &raw const (*_1); // scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
130+
StorageLive(_17); // scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
131+
_11 = (*_12); // scope 10 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
132+
StorageDead(_17); // scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
133+
StorageDead(_12); // scope 6 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
134+
StorageLive(_14); // scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
135+
_14 = &raw const (*_2); // scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
136+
StorageLive(_18); // scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
137+
_13 = (*_14); // scope 13 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
138+
StorageDead(_18); // scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
139+
StorageDead(_14); // scope 7 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
140+
StorageLive(_15); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
141+
_15 = &raw mut (*_1); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
142+
StorageLive(_19); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
143+
(*_15) = move _13; // scope 16 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
144+
StorageDead(_19); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
145+
StorageDead(_15); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
146+
StorageLive(_16); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
147+
_16 = &raw mut (*_2); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
148+
StorageLive(_20); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
149+
(*_16) = move _11; // scope 19 at $SRC_DIR/core/src/ptr/mod.rs:LL:COL
150+
StorageDead(_20); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
151+
StorageDead(_16); // scope 8 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
152+
StorageDead(_13); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
153+
StorageDead(_11); // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
154+
goto -> bb1; // scope 1 at $SRC_DIR/core/src/mem/mod.rs:LL:COL
155+
}
156+
}

0 commit comments

Comments
 (0)