Skip to content

Commit

Permalink
Auto merge of #115140 - wesleywiser:turn_off_mir_sroa, r=cuviper
Browse files Browse the repository at this point in the history
Disable MIR SROA optimization by default

Turn off the MIR SROA optimization by default to prevent incorrect debuginfo generation and rustc ICEs caused by invalid LLVM IR being created.

Related to #115113

r? `@cuviper`
cc `@saethlin`
  • Loading branch information
bors committed Aug 23, 2023
2 parents f155f8c + 298ec52 commit 5680fa1
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 213 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/sroa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ScalarReplacementOfAggregates;

impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 2
sess.mir_opt_level() >= 3
}

#[instrument(level = "debug", skip(self, tcx, body))]
Expand Down
2 changes: 1 addition & 1 deletion tests/incremental/hashes/match_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 {

// Ignore optimized_mir in cfail2, the only change to optimized MIR is a span.
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck")]
#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck")]
#[rustc_clean(cfg="cfail3")]
#[rustc_clean(cfg="cfail5", except="hir_owner_nodes,optimized_mir,typeck")]
#[rustc_clean(cfg="cfail6")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,37 @@
+ debug ptr => _11;
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
+ debug self => _11;
+ let mut _15: std::ptr::NonNull<u8>;
+ let mut _16: std::ptr::NonNull<u8>;
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
+ debug self => _11;
+ let mut _16: *mut u8;
+ let mut _17: *mut [u8];
+ let mut _17: *mut u8;
+ let mut _18: *mut [u8];
+ scope 20 {
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
+ debug self => _11;
+ let mut _18: *const [u8];
+ let mut _19: *const [u8];
+ }
+ scope 22 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
+ debug self => _17;
+ debug self => _18;
+ }
+ scope 23 (inlined NonNull::<u8>::new_unchecked) {
+ debug ptr => _16;
+ let mut _19: *const u8;
+ debug ptr => _17;
+ let mut _20: *const u8;
+ let mut _21: *mut u8;
+ scope 24 {
+ scope 25 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
+ debug ptr => _16;
+ debug ptr => _21;
+ scope 26 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
+ debug self => _16;
+ let mut _20: *mut u8;
+ debug self => _21;
+ let mut _22: *mut u8;
+ scope 27 {
+ scope 28 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
+ debug ptr => _20;
+ debug ptr => _22;
+ scope 29 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
+ debug self => _20;
+ debug self => _22;
+ scope 30 {
+ scope 31 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
+ debug self => _20;
+ debug self => _22;
+ }
+ }
+ }
Expand All @@ -75,8 +76,8 @@
+ }
+ }
+ scope 32 (inlined NonNull::<u8>::as_ptr) {
+ debug self => _15;
+ let mut _21: *const u8;
+ debug self => _16;
+ let mut _23: *const u8;
+ }
+ }
+ }
Expand All @@ -93,13 +94,14 @@
+ scope 10 {
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
+ debug align => _5;
+ let mut _15: usize;
+ scope 12 {
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
+ debug align => _5;
+ debug align => _15;
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
+ debug self => _5;
+ debug self => _15;
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
+ debug self => _5;
+ debug self => _15;
+ }
+ }
+ }
Expand Down Expand Up @@ -129,7 +131,9 @@
+ StorageLive(_12);
+ StorageLive(_13);
+ StorageLive(_14);
+ StorageLive(_15);
+ _14 = _5 as std::ptr::Alignment (Transmute);
+ StorageDead(_15);
+ _8 = Layout { size: _4, align: move _14 };
+ StorageDead(_14);
+ StorageLive(_9);
Expand All @@ -153,27 +157,29 @@
+
+ bb4: {
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
+ StorageLive(_15);
+ StorageLive(_16);
+ StorageLive(_17);
+ StorageLive(_18);
+ _18 = (_11.0: *const [u8]);
+ _17 = move _18 as *mut [u8] (PtrToPtr);
+ StorageDead(_18);
+ _16 = _17 as *mut u8 (PtrToPtr);
+ StorageDead(_17);
+ StorageLive(_19);
+ StorageLive(_20);
+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
+ _15 = NonNull::<u8> { pointer: _19 };
+ StorageDead(_20);
+ _19 = (_11.0: *const [u8]);
+ _18 = move _19 as *mut [u8] (PtrToPtr);
+ StorageDead(_19);
+ StorageDead(_16);
+ _17 = _18 as *mut u8 (PtrToPtr);
+ StorageDead(_18);
+ StorageLive(_20);
+ StorageLive(_21);
+ _21 = (_15.0: *const u8);
+ _6 = move _21 as *mut u8 (PtrToPtr);
+ StorageLive(_22);
+ _20 = _17 as *const u8 (PointerCoercion(MutToConstPointer));
+ _16 = NonNull::<u8> { pointer: _20 };
+ StorageDead(_22);
+ StorageDead(_21);
+ StorageDead(_15);
+ StorageDead(_20);
+ StorageDead(_17);
+ StorageLive(_23);
+ _23 = (_16.0: *const u8);
+ _6 = move _23 as *mut u8 (PtrToPtr);
+ StorageDead(_23);
+ StorageDead(_16);
+ StorageDead(_9);
+ StorageDead(_13);
+ StorageDead(_12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,37 @@
+ debug ptr => _11;
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
+ debug self => _11;
+ let mut _15: std::ptr::NonNull<u8>;
+ let mut _16: std::ptr::NonNull<u8>;
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
+ debug self => _11;
+ let mut _16: *mut u8;
+ let mut _17: *mut [u8];
+ let mut _17: *mut u8;
+ let mut _18: *mut [u8];
+ scope 20 {
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
+ debug self => _11;
+ let mut _18: *const [u8];
+ let mut _19: *const [u8];
+ }
+ scope 22 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
+ debug self => _17;
+ debug self => _18;
+ }
+ scope 23 (inlined NonNull::<u8>::new_unchecked) {
+ debug ptr => _16;
+ let mut _19: *const u8;
+ debug ptr => _17;
+ let mut _20: *const u8;
+ let mut _21: *mut u8;
+ scope 24 {
+ scope 25 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
+ debug ptr => _16;
+ debug ptr => _21;
+ scope 26 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
+ debug self => _16;
+ let mut _20: *mut u8;
+ debug self => _21;
+ let mut _22: *mut u8;
+ scope 27 {
+ scope 28 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
+ debug ptr => _20;
+ debug ptr => _22;
+ scope 29 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
+ debug self => _20;
+ debug self => _22;
+ scope 30 {
+ scope 31 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
+ debug self => _20;
+ debug self => _22;
+ }
+ }
+ }
Expand All @@ -75,8 +76,8 @@
+ }
+ }
+ scope 32 (inlined NonNull::<u8>::as_ptr) {
+ debug self => _15;
+ let mut _21: *const u8;
+ debug self => _16;
+ let mut _23: *const u8;
+ }
+ }
+ }
Expand All @@ -93,13 +94,14 @@
+ scope 10 {
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
+ debug align => _5;
+ let mut _15: usize;
+ scope 12 {
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
+ debug align => _5;
+ debug align => _15;
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
+ debug self => _5;
+ debug self => _15;
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
+ debug self => _5;
+ debug self => _15;
+ }
+ }
+ }
Expand Down Expand Up @@ -129,7 +131,9 @@
+ StorageLive(_12);
+ StorageLive(_13);
+ StorageLive(_14);
+ StorageLive(_15);
+ _14 = _5 as std::ptr::Alignment (Transmute);
+ StorageDead(_15);
+ _8 = Layout { size: _4, align: move _14 };
+ StorageDead(_14);
+ StorageLive(_9);
Expand Down Expand Up @@ -170,27 +174,29 @@
+
+ bb6: {
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
+ StorageLive(_15);
+ StorageLive(_16);
+ StorageLive(_17);
+ StorageLive(_18);
+ _18 = (_11.0: *const [u8]);
+ _17 = move _18 as *mut [u8] (PtrToPtr);
+ StorageDead(_18);
+ _16 = _17 as *mut u8 (PtrToPtr);
+ StorageDead(_17);
+ StorageLive(_19);
+ StorageLive(_20);
+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
+ _15 = NonNull::<u8> { pointer: _19 };
+ StorageDead(_20);
+ _19 = (_11.0: *const [u8]);
+ _18 = move _19 as *mut [u8] (PtrToPtr);
+ StorageDead(_19);
+ StorageDead(_16);
+ _17 = _18 as *mut u8 (PtrToPtr);
+ StorageDead(_18);
+ StorageLive(_20);
+ StorageLive(_21);
+ _21 = (_15.0: *const u8);
+ _6 = move _21 as *mut u8 (PtrToPtr);
+ StorageLive(_22);
+ _20 = _17 as *const u8 (PointerCoercion(MutToConstPointer));
+ _16 = NonNull::<u8> { pointer: _20 };
+ StorageDead(_22);
+ StorageDead(_21);
+ StorageDead(_15);
+ StorageDead(_20);
+ StorageDead(_17);
+ StorageLive(_23);
+ _23 = (_16.0: *const u8);
+ _6 = move _23 as *mut u8 (PtrToPtr);
+ StorageDead(_23);
+ StorageDead(_16);
+ StorageDead(_9);
+ StorageDead(_13);
+ StorageDead(_12);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
scope 1 (inlined core::num::<impl u32>::checked_shl) {
debug self => _1;
debug rhs => _2;
let mut _7: bool;
let mut _7: (u32, bool);
let _8: u32;
let _9: bool;
let mut _10: bool;
scope 2 {
debug a => _5;
debug b => _6;
debug a => _8;
debug b => _9;
}
scope 3 (inlined core::num::<impl u32>::overflowing_shl) {
debug self => _1;
Expand All @@ -35,26 +38,35 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
}

bb0: {
StorageLive(_8);
StorageLive(_9);
StorageLive(_7);
StorageLive(_5);
StorageLive(_6);
StorageLive(_4);
StorageLive(_3);
_3 = const 31_u32;
_4 = BitAnd(_2, move _3);
StorageDead(_3);
_5 = ShlUnchecked(_1, _4);
StorageDead(_4);
StorageLive(_6);
_6 = Ge(_2, const _);
StorageLive(_7);
_7 = unlikely(_6) -> [return: bb1, unwind unreachable];
_7 = (move _5, move _6);
StorageDead(_6);
StorageDead(_5);
_8 = (_7.0: u32);
_9 = (_7.1: bool);
StorageDead(_7);
StorageLive(_10);
_10 = unlikely(_9) -> [return: bb1, unwind unreachable];
}

bb1: {
switchInt(move _7) -> [0: bb2, otherwise: bb3];
switchInt(move _10) -> [0: bb2, otherwise: bb3];
}

bb2: {
_0 = Option::<u32>::Some(_5);
_0 = Option::<u32>::Some(_8);
goto -> bb4;
}

Expand All @@ -64,9 +76,9 @@ fn checked_shl(_1: u32, _2: u32) -> Option<u32> {
}

bb4: {
StorageDead(_7);
StorageDead(_6);
StorageDead(_5);
StorageDead(_10);
StorageDead(_9);
StorageDead(_8);
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
scope 7 (inlined std::ptr::write::<u32>) {
debug dst => _4;
debug src => _2;
let mut _6: *mut u32;
scope 8 {
scope 9 (inlined std::ptr::write::runtime::<u32>) {
debug dst => _4;
debug dst => _6;
}
}
}
}
scope 4 (inlined std::ptr::read::<u32>) {
debug src => _3;
let mut _5: *const u32;
scope 5 {
scope 6 (inlined std::ptr::read::runtime::<u32>) {
debug src => _3;
debug src => _5;
}
}
}
Expand All @@ -36,11 +38,15 @@ fn mem_replace(_1: &mut u32, _2: u32) -> u32 {
bb0: {
StorageLive(_3);
_3 = &raw const (*_1);
StorageLive(_5);
_0 = (*_3);
StorageDead(_5);
StorageDead(_3);
StorageLive(_4);
_4 = &raw mut (*_1);
StorageLive(_6);
(*_4) = _2;
StorageDead(_6);
StorageDead(_4);
return;
}
Expand Down
Loading

0 comments on commit 5680fa1

Please sign in to comment.