Skip to content

Commit dfe3188

Browse files
committed
Auto merge of #111007 - JakobDegen:nrvo, r=tmiasko
Disable nrvo mir opt See #111005 and #110902 . The ICE can definitely be hit on stable, the miscompilation I'm not sure about. The pass makes some pretty sketchy assumptions though, and we should not have it on while that's the case. I'm not going to work on actually fixing this, it's probably not excessively difficult though. r? rust-lang/mir-opt
2 parents a0111af + 8e2da80 commit dfe3188

20 files changed

+247
-574
lines changed

compiler/rustc_mir_transform/src/nrvo.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub struct RenameReturnPlace;
3434

3535
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
3636
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
37-
sess.mir_opt_level() > 0
37+
// #111005
38+
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
3839
}
3940

4041
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {

tests/codegen/fewer-names.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
#[no_mangle]
99
pub fn sum(x: u32, y: u32) -> u32 {
10-
// YES-LABEL: define{{.*}}i32 @sum(i32 noundef %0, i32 noundef %1)
11-
// YES-NEXT: %3 = add i32 %1, %0
12-
// YES-NEXT: ret i32 %3
10+
// YES-LABEL: define{{.*}}i32 @sum(i32 noundef %0, i32 noundef %1)
11+
// YES-NEXT: %3 = add i32 %1, %0
12+
// YES-NEXT: ret i32 %3
1313

14-
// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
15-
// NO-NEXT: start:
16-
// NO-NEXT: %0 = add i32 %y, %x
17-
// NO-NEXT: ret i32 %0
14+
// NO-LABEL: define{{.*}}i32 @sum(i32 noundef %x, i32 noundef %y)
15+
// NO-NEXT: start:
16+
// NO-NEXT: %z = add i32 %y, %x
17+
// NO-NEXT: ret i32 %z
1818
let z = x + y;
1919
z
2020
}

tests/codegen/mem-replace-big-type.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub struct Big([u64; 7]);
1313
pub fn replace_big(dst: &mut Big, src: Big) -> Big {
1414
// Back in 1.68, this emitted six `memcpy`s.
1515
// `read_via_copy` in 1.69 got that down to three.
16-
// `write_via_move` has it down to just the two essential ones.
16+
// `write_via_move` it was originally down to the essential two, however
17+
// with nrvo disabled it is back at 3
1718
std::mem::replace(dst, src)
1819
}
1920

@@ -22,13 +23,14 @@ pub fn replace_big(dst: &mut Big, src: Big) -> Big {
2223

2324
// CHECK-NOT: call void @llvm.memcpy
2425

25-
// For a large type, we expect exactly two `memcpy`s
26+
// For a large type, we expect exactly three `memcpy`s
2627
// CHECK-LABEL: define internal void @{{.+}}mem{{.+}}replace{{.+}}sret(%Big)
27-
// CHECK-NOT: alloca
28-
// CHECK-NOT: call void @llvm.memcpy
29-
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %0, {{i8\*|ptr}} align 8 %dest, i{{.*}} 56, i1 false)
30-
// CHECK-NOT: call void @llvm.memcpy
31-
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %dest, {{i8\*|ptr}} align 8 %src, i{{.*}} 56, i1 false)
32-
// CHECK-NOT: call void @llvm.memcpy
28+
// CHECK-NOT: call void @llvm.memcpy
29+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %result, {{i8\*|ptr}} align 8 %dest, i{{.*}} 56, i1 false)
30+
// CHECK-NOT: call void @llvm.memcpy
31+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %dest, {{i8\*|ptr}} align 8 %src, i{{.*}} 56, i1 false)
32+
// CHECK-NOT: call void @llvm.memcpy
33+
// CHECK: call void @llvm.memcpy.{{.+}}({{i8\*|ptr}} align 8 %0, {{i8\*|ptr}} align 8 %result, i{{.*}} 56, i1 false)
34+
// CHECK-NOT: call void @llvm.memcpy
3335

3436
// CHECK-NOT: call void @llvm.memcpy

tests/codegen/nrvo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pub fn nrvo(init: fn(&mut [u8; 4096])) -> [u8; 4096] {
99
// CHECK-LABEL: nrvo
1010
// CHECK: @llvm.memset
11-
// CHECK-NOT: @llvm.memcpy
11+
// FIXME: turn on nrvo then check-not: @llvm.memcpy
1212
// CHECK: ret
1313
// CHECK-EMPTY
1414
let mut buf = [0; 4096];

tests/codegen/var-names.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub fn test(a: u32, b: u32) -> u32 {
99
// CHECK: %c = add i32 %a, %b
1010
let d = c;
1111
let e = d * a;
12-
// CHECK-NEXT: %0 = mul i32 %c, %a
12+
// CHECK-NEXT: %e = mul i32 %c, %a
1313
e
14-
// CHECK-NEXT: ret i32 %0
14+
// CHECK-NEXT: ret i32 %e
1515
}

tests/mir-opt/inline/inline_into_box_place.main.Inline.diff

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
+ let mut _4: usize; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
1717
+ let mut _5: usize; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
1818
+ let mut _6: *mut u8; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
19-
+ let mut _7: *const std::vec::Vec<u32>; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
19+
+ let mut _7: std::boxed::Box<std::vec::Vec<u32>>; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
20+
+ let mut _8: *const std::vec::Vec<u32>; // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2021
+ scope 4 {
2122
+ }
2223
+ }
@@ -65,9 +66,12 @@
6566
bb3: {
6667
- StorageDead(_1); // scope 0 at $DIR/inline_into_box_place.rs:+2:1: +2:2
6768
- return; // scope 0 at $DIR/inline_into_box_place.rs:+2:2: +2:2
68-
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
69-
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
70-
+ (*_7) = move _2; // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
69+
+ StorageLive(_7); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
70+
+ _7 = ShallowInitBox(move _6, std::vec::Vec<u32>); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
71+
+ _8 = (((_7.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
72+
+ (*_8) = move _2; // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
73+
+ _1 = move _7; // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
74+
+ StorageDead(_7); // scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
7175
+ StorageDead(_2); // scope 0 at $DIR/inline_into_box_place.rs:+1:48: +1:49
7276
+ _0 = const (); // scope 0 at $DIR/inline_into_box_place.rs:+0:11: +2:2
7377
+ drop(_1) -> [return: bb1, unwind: bb2]; // scope 0 at $DIR/inline_into_box_place.rs:+2:1: +2:2

tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.b.Inline.after.mir

+9-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ fn b(_1: &mut Box<T>) -> &mut T {
88
let mut _4: &mut std::boxed::Box<T>; // in scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
99
scope 1 (inlined <Box<T> as AsMut<T>>::as_mut) { // at $DIR/issue_58867_inline_as_ref_as_mut.rs:8:7: 8:15
1010
debug self => _4; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
11-
let mut _5: std::boxed::Box<T>; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
12-
let mut _6: *const T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
11+
let mut _5: &mut T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
12+
let mut _6: std::boxed::Box<T>; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
13+
let mut _7: *const T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
1314
}
1415

1516
bb0: {
1617
StorageLive(_2); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
1718
StorageLive(_3); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
1819
StorageLive(_4); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
1920
_4 = &mut (*_1); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
20-
_5 = deref_copy (*_4); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
21-
_6 = (((_5.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
22-
_3 = &mut (*_6); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
21+
StorageLive(_5); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:7: +1:15
22+
_6 = deref_copy (*_4); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
23+
_7 = (((_6.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
24+
_5 = &mut (*_7); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
25+
_3 = _5; // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
26+
StorageDead(_5); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:7: +1:15
2327
_2 = &mut (*_3); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
2428
StorageDead(_4); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:14: +1:15
2529
_0 = &mut (*_2); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15

tests/mir-opt/inline/issue_58867_inline_as_ref_as_mut.d.Inline.after.mir

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ fn d(_1: &Box<T>) -> &T {
77
let mut _3: &std::boxed::Box<T>; // in scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
88
scope 1 (inlined <Box<T> as AsRef<T>>::as_ref) { // at $DIR/issue_58867_inline_as_ref_as_mut.rs:18:7: 18:15
99
debug self => _3; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
10-
let mut _4: std::boxed::Box<T>; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
11-
let mut _5: *const T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
10+
let _4: &T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
11+
let mut _5: std::boxed::Box<T>; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
12+
let mut _6: *const T; // in scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
1213
}
1314

1415
bb0: {
1516
StorageLive(_2); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
1617
StorageLive(_3); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
1718
_3 = &(*_1); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
18-
_4 = deref_copy (*_3); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
19-
_5 = (((_4.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
20-
_2 = &(*_5); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
19+
StorageLive(_4); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
20+
_5 = deref_copy (*_3); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
21+
_6 = (((_5.0: std::ptr::Unique<T>).0: std::ptr::NonNull<T>).0: *const T); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
22+
_4 = &(*_6); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
23+
_2 = _4; // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
24+
StorageDead(_4); // scope 1 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
2125
_0 = &(*_2); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:5: +1:15
2226
StorageDead(_3); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+1:14: +1:15
2327
StorageDead(_2); // scope 0 at $DIR/issue_58867_inline_as_ref_as_mut.rs:+2:1: +2:2

0 commit comments

Comments
 (0)