Skip to content

Commit

Permalink
Add a mir-opt test for byte_add on pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Apr 21, 2024
1 parent b76faff commit 70df9d9
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// MIR for `demo_byte_add_fat` after PreCodegen

fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
debug p => _1;
debug n => _2;
let mut _0: *const [u32];
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
let mut _7: usize;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
}
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _5;
debug metadata => _7;
let mut _8: std::ptr::metadata::PtrComponents<[u32]>;
let mut _9: std::ptr::metadata::PtrRepr<[u32]>;
}
}
}

bb0: {
StorageLive(_4);
StorageLive(_3);
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
StorageLive(_7);
StorageLive(_6);
_6 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _1 };
_7 = ((_6.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize);
StorageDead(_6);
StorageLive(_9);
StorageLive(_8);
_8 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: _5, metadata: _7 };
_9 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _8 };
StorageDead(_8);
_0 = (_9.0: *const [u32]);
StorageDead(_9);
StorageDead(_7);
StorageDead(_5);
StorageDead(_4);
return;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// MIR for `demo_byte_add_fat` after PreCodegen

fn demo_byte_add_fat(_1: *const [u32], _2: usize) -> *const [u32] {
debug p => _1;
debug n => _2;
let mut _0: *const [u32];
scope 1 (inlined std::ptr::const_ptr::<impl *const [u32]>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const [u32]>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<[u32]>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
let mut _7: usize;
scope 5 (inlined std::ptr::metadata::<[u32]>) {
debug ptr => _1;
let mut _6: std::ptr::metadata::PtrRepr<[u32]>;
}
scope 6 (inlined std::ptr::from_raw_parts::<[u32]>) {
debug data_pointer => _5;
debug metadata => _7;
let mut _8: std::ptr::metadata::PtrComponents<[u32]>;
let mut _9: std::ptr::metadata::PtrRepr<[u32]>;
}
}
}

bb0: {
StorageLive(_4);
StorageLive(_3);
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
StorageLive(_7);
StorageLive(_6);
_6 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: _1 };
_7 = ((_6.2: std::ptr::metadata::PtrComponents<[u32]>).1: usize);
StorageDead(_6);
StorageLive(_9);
StorageLive(_8);
_8 = std::ptr::metadata::PtrComponents::<[u32]> { data_pointer: _5, metadata: _7 };
_9 = std::ptr::metadata::PtrRepr::<[u32]> { const_ptr: move _8 };
StorageDead(_8);
_0 = (_9.0: *const [u32]);
StorageDead(_9);
StorageDead(_7);
StorageDead(_5);
StorageDead(_4);
return;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// MIR for `demo_byte_add_thin` after PreCodegen

fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
debug p => _1;
debug n => _2;
let mut _0: *const u32;
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
scope 5 (inlined std::ptr::metadata::<u32>) {
debug ptr => _1;
}
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
debug data_pointer => _5;
debug metadata => const ();
let mut _6: std::ptr::metadata::PtrComponents<u32>;
let mut _7: std::ptr::metadata::PtrRepr<u32>;
}
}
}

bb0: {
StorageLive(_4);
StorageLive(_3);
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
StorageLive(_7);
StorageLive(_6);
_6 = std::ptr::metadata::PtrComponents::<u32> { data_pointer: _5, metadata: const () };
_7 = std::ptr::metadata::PtrRepr::<u32> { const_ptr: move _6 };
StorageDead(_6);
_0 = (_7.0: *const u32);
StorageDead(_7);
StorageDead(_5);
StorageDead(_4);
return;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// MIR for `demo_byte_add_thin` after PreCodegen

fn demo_byte_add_thin(_1: *const u32, _2: usize) -> *const u32 {
debug p => _1;
debug n => _2;
let mut _0: *const u32;
scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::byte_add) {
debug self => _1;
debug count => _2;
let mut _3: *const u8;
let mut _4: *const u8;
scope 2 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<u8>) {
debug self => _1;
}
scope 3 (inlined std::ptr::const_ptr::<impl *const u8>::add) {
debug self => _3;
debug count => _2;
}
scope 4 (inlined std::ptr::const_ptr::<impl *const u8>::with_metadata_of::<u32>) {
debug self => _4;
debug meta => _1;
let mut _5: *const ();
scope 5 (inlined std::ptr::metadata::<u32>) {
debug ptr => _1;
}
scope 6 (inlined std::ptr::from_raw_parts::<u32>) {
debug data_pointer => _5;
debug metadata => const ();
let mut _6: std::ptr::metadata::PtrComponents<u32>;
let mut _7: std::ptr::metadata::PtrRepr<u32>;
}
}
}

bb0: {
StorageLive(_4);
StorageLive(_3);
_3 = _1 as *const u8 (PtrToPtr);
_4 = Offset(_3, _2);
StorageDead(_3);
StorageLive(_5);
_5 = _4 as *const () (PtrToPtr);
StorageLive(_7);
StorageLive(_6);
_6 = std::ptr::metadata::PtrComponents::<u32> { data_pointer: _5, metadata: const () };
_7 = std::ptr::metadata::PtrRepr::<u32> { const_ptr: move _6 };
StorageDead(_6);
_0 = (_7.0: *const u32);
StorageDead(_7);
StorageDead(_5);
StorageDead(_4);
return;
}
}
16 changes: 16 additions & 0 deletions tests/mir-opt/pre-codegen/ptr_offset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// skip-filecheck
//@ compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2 -Zinline-mir
//@ ignore-debug: precondition checks are under cfg(debug_assertions)
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![crate_type = "lib"]

// EMIT_MIR ptr_offset.demo_byte_add_thin.PreCodegen.after.mir
pub unsafe fn demo_byte_add_thin(p: *const u32, n: usize) -> *const u32 {
p.byte_add(n)
}

// EMIT_MIR ptr_offset.demo_byte_add_fat.PreCodegen.after.mir
pub unsafe fn demo_byte_add_fat(p: *const [u32], n: usize) -> *const [u32] {
p.byte_add(n)
}

0 comments on commit 70df9d9

Please sign in to comment.