Skip to content

Commit 00608ef

Browse files
committed
INSTR_COST=2.
1 parent a1a8c4a commit 00608ef

6 files changed

+856
-65
lines changed

compiler/rustc_mir_transform/src/cost_checker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_middle::mir::visit::*;
22
use rustc_middle::mir::*;
33
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
44

5-
const INSTR_COST: usize = 3;
5+
const INSTR_COST: usize = 2;
66
const CALL_PENALTY: usize = 25;
77
const LANDINGPAD_PENALTY: usize = 50;
88
const RESUME_PENALTY: usize = 45;

tests/mir-opt/pre-codegen/checked_ops.step_forward.PreCodegen.after.mir

+172-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,183 @@ fn step_forward(_1: u32, _2: usize) -> u32 {
44
debug x => _1;
55
debug n => _2;
66
let mut _0: u32;
7+
scope 1 (inlined <u32 as Step>::forward) {
8+
debug start => _1;
9+
debug n => _2;
10+
let _12: std::option::Option<u32>;
11+
let mut _13: &std::option::Option<u32>;
12+
let mut _16: bool;
13+
let mut _17: u32;
14+
scope 2 {
15+
}
16+
scope 3 (inlined <u32 as Step>::forward_checked) {
17+
debug start => _1;
18+
debug n => _2;
19+
let mut _5: std::result::Result<u32, std::num::TryFromIntError>;
20+
let mut _6: isize;
21+
let _7: u32;
22+
scope 4 {
23+
debug n => _7;
24+
scope 6 (inlined core::num::<impl u32>::checked_add) {
25+
debug self => _1;
26+
debug rhs => _7;
27+
let mut _11: bool;
28+
scope 7 {
29+
debug a => _9;
30+
debug b => _10;
31+
}
32+
scope 8 (inlined core::num::<impl u32>::overflowing_add) {
33+
debug self => _1;
34+
debug rhs => _7;
35+
let mut _8: (u32, bool);
36+
let _9: u32;
37+
let _10: bool;
38+
scope 9 {
39+
debug a => _9;
40+
debug b => _10;
41+
}
42+
}
43+
}
44+
}
45+
scope 5 (inlined convert::num::ptr_try_from_impls::<impl TryFrom<usize> for u32>::try_from) {
46+
debug u => _2;
47+
let mut _3: bool;
48+
let mut _4: u32;
49+
}
50+
}
51+
scope 10 (inlined Option::<u32>::is_none) {
52+
debug self => _13;
53+
let mut _15: bool;
54+
scope 11 (inlined Option::<u32>::is_some) {
55+
debug self => _13;
56+
let mut _14: isize;
57+
}
58+
}
59+
scope 12 (inlined core::num::<impl u32>::wrapping_add) {
60+
debug self => _1;
61+
debug rhs => _17;
62+
}
63+
}
764

865
bb0: {
9-
_0 = <u32 as Step>::forward(move _1, move _2) -> [return: bb1, unwind continue];
66+
StorageLive(_16);
67+
StorageLive(_13);
68+
StorageLive(_12);
69+
StorageLive(_6);
70+
StorageLive(_7);
71+
StorageLive(_5);
72+
StorageLive(_3);
73+
_3 = Gt(_2, const 4294967295_usize);
74+
switchInt(move _3) -> [0: bb1, otherwise: bb2];
1075
}
1176

1277
bb1: {
78+
StorageLive(_4);
79+
_4 = _2 as u32 (IntToInt);
80+
_5 = Result::<u32, TryFromIntError>::Ok(move _4);
81+
StorageDead(_4);
82+
goto -> bb3;
83+
}
84+
85+
bb2: {
86+
_5 = const Result::<u32, TryFromIntError>::Err(TryFromIntError(()));
87+
goto -> bb3;
88+
}
89+
90+
bb3: {
91+
StorageDead(_3);
92+
_6 = discriminant(_5);
93+
switchInt(move _6) -> [0: bb4, 1: bb9, otherwise: bb14];
94+
}
95+
96+
bb4: {
97+
_7 = ((_5 as Ok).0: u32);
98+
StorageLive(_9);
99+
StorageLive(_10);
100+
StorageLive(_8);
101+
_8 = CheckedAdd(_1, _7);
102+
_9 = (_8.0: u32);
103+
_10 = (_8.1: bool);
104+
StorageDead(_8);
105+
StorageLive(_11);
106+
_11 = unlikely(move _10) -> [return: bb5, unwind unreachable];
107+
}
108+
109+
bb5: {
110+
switchInt(move _11) -> [0: bb6, otherwise: bb7];
111+
}
112+
113+
bb6: {
114+
_12 = Option::<u32>::Some(_9);
115+
goto -> bb8;
116+
}
117+
118+
bb7: {
119+
_12 = const Option::<u32>::None;
120+
goto -> bb8;
121+
}
122+
123+
bb8: {
124+
StorageDead(_11);
125+
StorageDead(_10);
126+
StorageDead(_9);
127+
goto -> bb10;
128+
}
129+
130+
bb9: {
131+
_12 = const Option::<u32>::None;
132+
goto -> bb10;
133+
}
134+
135+
bb10: {
136+
StorageDead(_5);
137+
StorageDead(_7);
138+
StorageDead(_6);
139+
_13 = &_12;
140+
StorageLive(_15);
141+
StorageLive(_14);
142+
_14 = discriminant(_12);
143+
_15 = Eq(_14, const 1_isize);
144+
StorageDead(_14);
145+
_16 = Not(move _15);
146+
StorageDead(_15);
147+
switchInt(move _16) -> [0: bb11, otherwise: bb12];
148+
}
149+
150+
bb11: {
151+
StorageDead(_12);
152+
StorageDead(_13);
153+
goto -> bb13;
154+
}
155+
156+
bb12: {
157+
StorageDead(_12);
158+
StorageDead(_13);
159+
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const _, const 1_u32) -> [success: bb13, unwind continue];
160+
}
161+
162+
bb13: {
163+
StorageDead(_16);
164+
StorageLive(_17);
165+
_17 = _2 as u32 (IntToInt);
166+
_0 = Add(_1, _17);
167+
StorageDead(_17);
13168
return;
14169
}
170+
171+
bb14: {
172+
unreachable;
173+
}
174+
}
175+
176+
ALLOC0 (size: 8, align: 4) {
177+
00 00 00 00 __ __ __ __ │ ....░░░░
178+
}
179+
180+
ALLOC1 (size: 8, align: 4) {
181+
01 00 00 00 __ __ __ __ │ ....░░░░
182+
}
183+
184+
ALLOC2 (size: 8, align: 4) {
185+
00 00 00 00 __ __ __ __ │ ....░░░░
15186
}

0 commit comments

Comments
 (0)