Skip to content

Commit 70df9d9

Browse files
committed
Add a mir-opt test for byte_add on pointers
1 parent b76faff commit 70df9d9

5 files changed

+248
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// MIR for `demo_byte_add_fat` after PreCodegen
2+
3+
fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
4+
debug p => _1;
5+
debug n => _2;
6+
let mut _0: *const [u32];
7+
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
8+
debug self => _1;
9+
debug count => _2;
10+
let mut _3: *const u8;
11+
let mut _4: *const u8;
12+
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
13+
debug self => _1;
14+
}
15+
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
16+
debug self => _3;
17+
debug count => _2;
18+
}
19+
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
20+
debug self => _4;
21+
debug meta => _1;
22+
let mut _5: *const ();
23+
let mut _7: usize;
24+
scope 5 (inlined std::ptr::metadata::<[u32]>) {
25+
debug ptr => _1;
26+
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
27+
}
28+
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
29+
debug data_pointer => _5;
30+
debug metadata => _7;
31+
let mut _8: std::ptr::metadata::PtrComponents<[u32]>;
32+
let mut _9: std::ptr::metadata::PtrRepr<[u32]>;
33+
}
34+
}
35+
}
36+
37+
bb0: {
38+
StorageLive(_4);
39+
StorageLive(_3);
40+
_3 = _1 as *const u8 (PtrToPtr);
41+
_4 = Offset(_3, _2);
42+
StorageDead(_3);
43+
StorageLive(_5);
44+
_5 = _4 as *const () (PtrToPtr);
45+
StorageLive(_7);
46+
StorageLive(_6);
47+
_6 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _1 };
48+
_7 = ((_6.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize);
49+
StorageDead(_6);
50+
StorageLive(_9);
51+
StorageLive(_8);
52+
_8 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: _5, metadata: _7 };
53+
_9 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _8 };
54+
StorageDead(_8);
55+
_0 = (_9.0: *const [u32]);
56+
StorageDead(_9);
57+
StorageDead(_7);
58+
StorageDead(_5);
59+
StorageDead(_4);
60+
return;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// MIR for `demo_byte_add_fat` after PreCodegen
2+
3+
fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
4+
debug p => _1;
5+
debug n => _2;
6+
let mut _0: *const [u32];
7+
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
8+
debug self => _1;
9+
debug count => _2;
10+
let mut _3: *const u8;
11+
let mut _4: *const u8;
12+
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
13+
debug self => _1;
14+
}
15+
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
16+
debug self => _3;
17+
debug count => _2;
18+
}
19+
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
20+
debug self => _4;
21+
debug meta => _1;
22+
let mut _5: *const ();
23+
let mut _7: usize;
24+
scope 5 (inlined std::ptr::metadata::<[u32]>) {
25+
debug ptr => _1;
26+
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
27+
}
28+
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
29+
debug data_pointer => _5;
30+
debug metadata => _7;
31+
let mut _8: std::ptr::metadata::PtrComponents<[u32]>;
32+
let mut _9: std::ptr::metadata::PtrRepr<[u32]>;
33+
}
34+
}
35+
}
36+
37+
bb0: {
38+
StorageLive(_4);
39+
StorageLive(_3);
40+
_3 = _1 as *const u8 (PtrToPtr);
41+
_4 = Offset(_3, _2);
42+
StorageDead(_3);
43+
StorageLive(_5);
44+
_5 = _4 as *const () (PtrToPtr);
45+
StorageLive(_7);
46+
StorageLive(_6);
47+
_6 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _1 };
48+
_7 = ((_6.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize);
49+
StorageDead(_6);
50+
StorageLive(_9);
51+
StorageLive(_8);
52+
_8 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: _5, metadata: _7 };
53+
_9 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _8 };
54+
StorageDead(_8);
55+
_0 = (_9.0: *const [u32]);
56+
StorageDead(_9);
57+
StorageDead(_7);
58+
StorageDead(_5);
59+
StorageDead(_4);
60+
return;
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// MIR for `demo_byte_add_thin` after PreCodegen
2+
3+
fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
4+
debug p => _1;
5+
debug n => _2;
6+
let mut _0: *const u32;
7+
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
8+
debug self => _1;
9+
debug count => _2;
10+
let mut _3: *const u8;
11+
let mut _4: *const u8;
12+
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
13+
debug self => _1;
14+
}
15+
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
16+
debug self => _3;
17+
debug count => _2;
18+
}
19+
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
20+
debug self => _4;
21+
debug meta => _1;
22+
let mut _5: *const ();
23+
scope 5 (inlined std::ptr::metadata::<u32>) {
24+
debug ptr => _1;
25+
}
26+
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
27+
debug data_pointer => _5;
28+
debug metadata => const ();
29+
let mut _6: std::ptr::metadata::PtrComponents<u32>;
30+
let mut _7: std::ptr::metadata::PtrRepr<u32>;
31+
}
32+
}
33+
}
34+
35+
bb0: {
36+
StorageLive(_4);
37+
StorageLive(_3);
38+
_3 = _1 as *const u8 (PtrToPtr);
39+
_4 = Offset(_3, _2);
40+
StorageDead(_3);
41+
StorageLive(_5);
42+
_5 = _4 as *const () (PtrToPtr);
43+
StorageLive(_7);
44+
StorageLive(_6);
45+
_6 = std::ptr::metadata::PtrComponents::<u32> { data_pointer: _5, metadata: const () };
46+
_7 = std::ptr::metadata::PtrRepr::<u32> { const_ptr: move _6 };
47+
StorageDead(_6);
48+
_0 = (_7.0: *const u32);
49+
StorageDead(_7);
50+
StorageDead(_5);
51+
StorageDead(_4);
52+
return;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// MIR for `demo_byte_add_thin` after PreCodegen
2+
3+
fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
4+
debug p => _1;
5+
debug n => _2;
6+
let mut _0: *const u32;
7+
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
8+
debug self => _1;
9+
debug count => _2;
10+
let mut _3: *const u8;
11+
let mut _4: *const u8;
12+
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
13+
debug self => _1;
14+
}
15+
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
16+
debug self => _3;
17+
debug count => _2;
18+
}
19+
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
20+
debug self => _4;
21+
debug meta => _1;
22+
let mut _5: *const ();
23+
scope 5 (inlined std::ptr::metadata::<u32>) {
24+
debug ptr => _1;
25+
}
26+
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
27+
debug data_pointer => _5;
28+
debug metadata => const ();
29+
let mut _6: std::ptr::metadata::PtrComponents<u32>;
30+
let mut _7: std::ptr::metadata::PtrRepr<u32>;
31+
}
32+
}
33+
}
34+
35+
bb0: {
36+
StorageLive(_4);
37+
StorageLive(_3);
38+
_3 = _1 as *const u8 (PtrToPtr);
39+
_4 = Offset(_3, _2);
40+
StorageDead(_3);
41+
StorageLive(_5);
42+
_5 = _4 as *const () (PtrToPtr);
43+
StorageLive(_7);
44+
StorageLive(_6);
45+
_6 = std::ptr::metadata::PtrComponents::<u32> { data_pointer: _5, metadata: const () };
46+
_7 = std::ptr::metadata::PtrRepr::<u32> { const_ptr: move _6 };
47+
StorageDead(_6);
48+
_0 = (_7.0: *const u32);
49+
StorageDead(_7);
50+
StorageDead(_5);
51+
StorageDead(_4);
52+
return;
53+
}
54+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// skip-filecheck
2+
//@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Zinline-mir
3+
//@ ignore-debug: precondition checks are under cfg(debug_assertions)
4+
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
5+
6+
#![crate_type = "lib"]
7+
8+
// EMIT_MIR ptr_offset.demo_byte_add_thin.PreCodegen.after.mir
9+
pub unsafe fn demo_byte_add_thin(p: *const u32, n: usize) -> *const u32 {
10+
p.byte_add(n)
11+
}
12+
13+
// EMIT_MIR ptr_offset.demo_byte_add_fat.PreCodegen.after.mir
14+
pub unsafe fn demo_byte_add_fat(p: *const [u32], n: usize) -> *const [u32] {
15+
p.byte_add(n)
16+
}

0 commit comments

Comments
 (0)