Skip to content

Commit 470feda

Browse files
committed
Auto merge of rust-lang#116708 - cjgillot:cheap-stmt, r=<try>
Reduce inlining cost for statement r? `@ghost`
2 parents e1de04a + b5e754c commit 470feda

18 files changed

+2776
-387
lines changed

compiler/rustc_mir_transform/src/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ops::{Range, RangeFrom};
2222

2323
pub(crate) mod cycle;
2424

25-
const INSTR_COST: usize = 5;
25+
const INSTR_COST: usize = 2;
2626
const CALL_PENALTY: usize = 25;
2727
const LANDINGPAD_PENALTY: usize = 50;
2828
const RESUME_PENALTY: usize = 45;

tests/codegen/issues/issue-37945.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub fn is_empty_1(xs: Iter<f32>) -> bool {
2525
pub fn is_empty_2(xs: Iter<f32>) -> bool {
2626
// CHECK-LABEL: @is_empty_2
2727
// CHECK-NEXT: start:
28-
// CHECK-NEXT: [[C:%.*]] = icmp ne ptr {{%xs.0|%xs.1}}, null
29-
// CHECK-NEXT: tail call void @llvm.assume(i1 [[C]])
28+
// SHOULD-CHECK-NEXT: [[C:%.*]] = icmp ne ptr {{%xs.0|%xs.1}}, null
29+
// SHOULD-CHECK-NEXT: tail call void @llvm.assume(i1 [[C]])
3030
// The order between %xs.0 and %xs.1 on the next line doesn't matter
3131
// and different LLVM versions produce different order.
3232
// CHECK-NEXT: [[D:%.*]] = icmp eq ptr {{%xs.0, %xs.1|%xs.1, %xs.0}}

tests/codegen/issues/issue-75978.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#[no_mangle]
77
pub fn test() -> u32 {
88
// CHECK-LABEL: @test(
9-
// CHECK: ret i32 13
9+
// SHOULD-CHECK: ret i32 13
1010
let s = [1, 2, 3, 4, 5, 6, 7];
1111

1212
let mut iter = s.iter();

tests/codegen/vec-shrink-panik.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn issue71861(vec: Vec<u32>) -> Box<[u32]> {
3737
// CHECK-LABEL: @issue75636
3838
#[no_mangle]
3939
pub fn issue75636<'a>(iter: &[&'a str]) -> Box<[&'a str]> {
40-
// CHECK-NOT: panic
40+
// SHOULD-CHECK-NOT: panic
4141
iter.iter().copied().collect()
4242
}
4343

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@
126126
+ StorageLive(_5);
127127
+ StorageLive(_6);
128128
+ StorageLive(_7);
129+
+ StorageLive(_12);
129130
+ _4 = SizeOf(std::vec::Vec<u32>);
130131
+ _5 = AlignOf(std::vec::Vec<u32>);
131132
+ StorageLive(_8);
132133
+ StorageLive(_10);
133134
+ StorageLive(_11);
134-
+ StorageLive(_12);
135135
+ StorageLive(_13);
136136
+ StorageLive(_14);
137137
+ _14 = _5 as std::ptr::Alignment (Transmute);
@@ -181,13 +181,13 @@
181181
+ StorageDead(_15);
182182
+ StorageDead(_9);
183183
+ StorageDead(_13);
184-
+ StorageDead(_12);
185184
+ StorageDead(_11);
186185
+ StorageDead(_10);
187186
+ StorageDead(_8);
188187
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>);
189188
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>);
190189
+ (*_7) = move _2;
190+
+ StorageDead(_12);
191191
+ StorageDead(_7);
192192
+ StorageDead(_6);
193193
+ StorageDead(_5);

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

+11-185
Original file line numberDiff line numberDiff line change
@@ -10,108 +10,6 @@
1010
}
1111
+ scope 2 (inlined Vec::<u32>::new) {
1212
+ let mut _3: alloc::raw_vec::RawVec<u32>;
13-
+ }
14-
+ scope 3 (inlined Box::<Vec<u32>>::new) {
15-
+ debug x => _2;
16-
+ let mut _4: usize;
17-
+ let mut _5: usize;
18-
+ let mut _6: *mut u8;
19-
+ let mut _7: *const std::vec::Vec<u32>;
20-
+ scope 4 {
21-
+ scope 5 (inlined alloc::alloc::exchange_malloc) {
22-
+ debug size => _4;
23-
+ debug align => _5;
24-
+ let _8: std::alloc::Layout;
25-
+ let mut _9: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
26-
+ let mut _10: isize;
27-
+ let mut _12: !;
28-
+ scope 6 {
29-
+ debug layout => _8;
30-
+ let _11: std::ptr::NonNull<[u8]>;
31-
+ let mut _13: &std::alloc::Global;
32-
+ scope 8 {
33-
+ debug ptr => _11;
34-
+ scope 18 (inlined NonNull::<[u8]>::as_mut_ptr) {
35-
+ debug self => _11;
36-
+ let mut _15: std::ptr::NonNull<u8>;
37-
+ scope 19 (inlined NonNull::<[u8]>::as_non_null_ptr) {
38-
+ debug self => _11;
39-
+ let mut _16: *mut u8;
40-
+ let mut _17: *mut [u8];
41-
+ scope 20 {
42-
+ scope 21 (inlined NonNull::<[u8]>::as_ptr) {
43-
+ debug self => _11;
44-
+ let mut _18: *const [u8];
45-
+ }
46-
+ scope 22 (inlined ptr::mut_ptr::<impl *mut [u8]>::as_mut_ptr) {
47-
+ debug self => _17;
48-
+ }
49-
+ scope 23 (inlined NonNull::<u8>::new_unchecked) {
50-
+ debug ptr => _16;
51-
+ let mut _19: *const u8;
52-
+ scope 24 {
53-
+ scope 25 (inlined NonNull::<T>::new_unchecked::runtime::<u8>) {
54-
+ debug ptr => _16;
55-
+ scope 26 (inlined ptr::mut_ptr::<impl *mut u8>::is_null) {
56-
+ debug self => _16;
57-
+ let mut _20: *mut u8;
58-
+ scope 27 {
59-
+ scope 28 (inlined ptr::mut_ptr::<impl *mut T>::is_null::runtime_impl) {
60-
+ debug ptr => _20;
61-
+ scope 29 (inlined ptr::mut_ptr::<impl *mut u8>::addr) {
62-
+ debug self => _20;
63-
+ scope 30 {
64-
+ scope 31 (inlined ptr::mut_ptr::<impl *mut u8>::cast::<()>) {
65-
+ debug self => _20;
66-
+ }
67-
+ }
68-
+ }
69-
+ }
70-
+ }
71-
+ }
72-
+ }
73-
+ }
74-
+ }
75-
+ }
76-
+ }
77-
+ scope 32 (inlined NonNull::<u8>::as_ptr) {
78-
+ debug self => _15;
79-
+ let mut _21: *const u8;
80-
+ }
81-
+ }
82-
+ }
83-
+ scope 17 (inlined <std::alloc::Global as Allocator>::allocate) {
84-
+ debug self => const _;
85-
+ debug layout => _8;
86-
+ }
87-
+ }
88-
+ scope 7 {
89-
+ scope 9 (inlined Layout::from_size_align_unchecked) {
90-
+ debug size => _4;
91-
+ debug align => _5;
92-
+ let mut _14: std::ptr::Alignment;
93-
+ scope 10 {
94-
+ scope 11 (inlined std::ptr::Alignment::new_unchecked) {
95-
+ debug align => _5;
96-
+ scope 12 {
97-
+ scope 14 (inlined std::ptr::Alignment::new_unchecked::runtime) {
98-
+ debug align => _5;
99-
+ scope 15 (inlined core::num::<impl usize>::is_power_of_two) {
100-
+ debug self => _5;
101-
+ scope 16 (inlined core::num::<impl usize>::count_ones) {
102-
+ debug self => _5;
103-
+ }
104-
+ }
105-
+ }
106-
+ }
107-
+ scope 13 {
108-
+ }
109-
+ }
110-
+ }
111-
+ }
112-
+ }
113-
+ }
114-
+ }
11513
+ }
11614

11715
bb0: {
@@ -122,101 +20,29 @@
12220
+ _3 = const _;
12321
+ _2 = Vec::<u32> { buf: move _3, len: const 0_usize };
12422
+ StorageDead(_3);
125-
+ StorageLive(_4);
126-
+ StorageLive(_5);
127-
+ StorageLive(_6);
128-
+ StorageLive(_7);
129-
+ _4 = SizeOf(std::vec::Vec<u32>);
130-
+ _5 = AlignOf(std::vec::Vec<u32>);
131-
+ StorageLive(_8);
132-
+ StorageLive(_10);
133-
+ StorageLive(_11);
134-
+ StorageLive(_12);
135-
+ StorageLive(_13);
136-
+ StorageLive(_14);
137-
+ _14 = _5 as std::ptr::Alignment (Transmute);
138-
+ _8 = Layout { size: _4, align: move _14 };
139-
+ StorageDead(_14);
140-
+ StorageLive(_9);
141-
+ _13 = const _;
142-
+ _9 = std::alloc::Global::alloc_impl(move _13, _8, const false) -> [return: bb7, unwind: bb3];
23+
+ _1 = Box::<Vec<u32>>::new(move _2) -> [return: bb1, unwind: bb3];
14324
}
14425

14526
bb1: {
14627
- _1 = Box::<Vec<u32>>::new(move _2) -> [return: bb2, unwind: bb4];
147-
+ StorageDead(_1);
148-
+ return;
149-
}
150-
28+
- }
29+
-
15130
- bb2: {
152-
- StorageDead(_2);
153-
- _0 = const ();
31+
StorageDead(_2);
32+
_0 = const ();
15433
- drop(_1) -> [return: bb3, unwind: bb4];
155-
+ bb2 (cleanup): {
156-
+ resume;
34+
+ drop(_1) -> [return: bb2, unwind: bb3];
15735
}
15836

15937
- bb3: {
160-
- StorageDead(_1);
161-
- return;
162-
+ bb3 (cleanup): {
163-
+ drop(_2) -> [return: bb2, unwind terminate(cleanup)];
38+
+ bb2: {
39+
StorageDead(_1);
40+
return;
16441
}
16542

16643
- bb4 (cleanup): {
167-
- resume;
168-
+ bb4: {
169-
+ _12 = handle_alloc_error(move _8) -> bb3;
170-
+ }
171-
+
172-
+ bb5: {
173-
+ unreachable;
174-
+ }
175-
+
176-
+ bb6: {
177-
+ _11 = ((_9 as Ok).0: std::ptr::NonNull<[u8]>);
178-
+ StorageLive(_15);
179-
+ StorageLive(_16);
180-
+ StorageLive(_17);
181-
+ StorageLive(_18);
182-
+ _18 = (_11.0: *const [u8]);
183-
+ _17 = move _18 as *mut [u8] (PtrToPtr);
184-
+ StorageDead(_18);
185-
+ _16 = _17 as *mut u8 (PtrToPtr);
186-
+ StorageDead(_17);
187-
+ StorageLive(_19);
188-
+ StorageLive(_20);
189-
+ _19 = _16 as *const u8 (PointerCoercion(MutToConstPointer));
190-
+ _15 = NonNull::<u8> { pointer: _19 };
191-
+ StorageDead(_20);
192-
+ StorageDead(_19);
193-
+ StorageDead(_16);
194-
+ StorageLive(_21);
195-
+ _21 = (_15.0: *const u8);
196-
+ _6 = move _21 as *mut u8 (PtrToPtr);
197-
+ StorageDead(_21);
198-
+ StorageDead(_15);
199-
+ StorageDead(_9);
200-
+ StorageDead(_13);
201-
+ StorageDead(_12);
202-
+ StorageDead(_11);
203-
+ StorageDead(_10);
204-
+ StorageDead(_8);
205-
+ _1 = ShallowInitBox(move _6, std::vec::Vec<u32>);
206-
+ _7 = (((_1.0: std::ptr::Unique<std::vec::Vec<u32>>).0: std::ptr::NonNull<std::vec::Vec<u32>>).0: *const std::vec::Vec<u32>);
207-
+ (*_7) = move _2;
208-
+ StorageDead(_7);
209-
+ StorageDead(_6);
210-
+ StorageDead(_5);
211-
+ StorageDead(_4);
212-
+ StorageDead(_2);
213-
+ _0 = const ();
214-
+ drop(_1) -> [return: bb1, unwind: bb2];
215-
+ }
216-
+
217-
+ bb7: {
218-
+ _10 = discriminant(_9);
219-
+ switchInt(move _10) -> [0: bb6, 1: bb4, otherwise: bb5];
44+
+ bb3 (cleanup): {
45+
resume;
22046
}
22147
}
22248

0 commit comments

Comments
 (0)