@@ -6,8 +6,8 @@ use rustc_middle::bug;
6
6
use rustc_middle:: mir:: * ;
7
7
use rustc_middle:: ty:: layout:: ValidityRequirement ;
8
8
use rustc_middle:: ty:: { self , layout, GenericArgsRef , ParamEnv , Ty , TyCtxt } ;
9
- use rustc_span:: sym;
10
9
use rustc_span:: symbol:: Symbol ;
10
+ use rustc_span:: { sym, DUMMY_SP } ;
11
11
use rustc_target:: spec:: abi:: Abi ;
12
12
13
13
use crate :: simplify:: simplify_duplicate_switch_targets;
@@ -49,12 +49,12 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
49
49
match statement. kind {
50
50
StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
51
51
if !preserve_ub_checks {
52
- ctx. simplify_ub_check ( & statement . source_info , rvalue) ;
52
+ ctx. simplify_ub_check ( rvalue) ;
53
53
}
54
- ctx. simplify_bool_cmp ( & statement . source_info , rvalue) ;
55
- ctx. simplify_ref_deref ( & statement . source_info , rvalue) ;
56
- ctx. simplify_len ( & statement . source_info , rvalue) ;
57
- ctx. simplify_ptr_aggregate ( & statement . source_info , rvalue) ;
54
+ ctx. simplify_bool_cmp ( rvalue) ;
55
+ ctx. simplify_ref_deref ( rvalue) ;
56
+ ctx. simplify_len ( rvalue) ;
57
+ ctx. simplify_ptr_aggregate ( rvalue) ;
58
58
ctx. simplify_cast ( rvalue) ;
59
59
}
60
60
_ => { }
@@ -76,23 +76,8 @@ struct InstSimplifyContext<'tcx, 'a> {
76
76
}
77
77
78
78
impl < ' tcx > InstSimplifyContext < ' tcx , ' _ > {
79
- fn should_simplify ( & self , source_info : & SourceInfo , rvalue : & Rvalue < ' tcx > ) -> bool {
80
- self . should_simplify_custom ( source_info, "Rvalue" , rvalue)
81
- }
82
-
83
- fn should_simplify_custom (
84
- & self ,
85
- source_info : & SourceInfo ,
86
- label : & str ,
87
- value : impl std:: fmt:: Debug ,
88
- ) -> bool {
89
- self . tcx . consider_optimizing ( || {
90
- format ! ( "InstSimplify - {label}: {value:?} SourceInfo: {source_info:?}" )
91
- } )
92
- }
93
-
94
79
/// Transform boolean comparisons into logical operations.
95
- fn simplify_bool_cmp ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
80
+ fn simplify_bool_cmp ( & self , rvalue : & mut Rvalue < ' tcx > ) {
96
81
match rvalue {
97
82
Rvalue :: BinaryOp ( op @ ( BinOp :: Eq | BinOp :: Ne ) , box ( a, b) ) => {
98
83
let new = match ( op, self . try_eval_bool ( a) , self . try_eval_bool ( b) ) {
@@ -123,9 +108,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
123
108
_ => None ,
124
109
} ;
125
110
126
- if let Some ( new) = new
127
- && self . should_simplify ( source_info, rvalue)
128
- {
111
+ if let Some ( new) = new {
129
112
* rvalue = new;
130
113
}
131
114
}
@@ -140,17 +123,13 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
140
123
}
141
124
142
125
/// Transform `&(*a)` ==> `a`.
143
- fn simplify_ref_deref ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
126
+ fn simplify_ref_deref ( & self , rvalue : & mut Rvalue < ' tcx > ) {
144
127
if let Rvalue :: Ref ( _, _, place) | Rvalue :: RawPtr ( _, place) = rvalue {
145
128
if let Some ( ( base, ProjectionElem :: Deref ) ) = place. as_ref ( ) . last_projection ( ) {
146
129
if rvalue. ty ( self . local_decls , self . tcx ) != base. ty ( self . local_decls , self . tcx ) . ty {
147
130
return ;
148
131
}
149
132
150
- if !self . should_simplify ( source_info, rvalue) {
151
- return ;
152
- }
153
-
154
133
* rvalue = Rvalue :: Use ( Operand :: Copy ( Place {
155
134
local : base. local ,
156
135
projection : self . tcx . mk_place_elems ( base. projection ) ,
@@ -160,36 +139,24 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
160
139
}
161
140
162
141
/// Transform `Len([_; N])` ==> `N`.
163
- fn simplify_len ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
142
+ fn simplify_len ( & self , rvalue : & mut Rvalue < ' tcx > ) {
164
143
if let Rvalue :: Len ( ref place) = * rvalue {
165
144
let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
166
145
if let ty:: Array ( _, len) = * place_ty. kind ( ) {
167
- if !self . should_simplify ( source_info, rvalue) {
168
- return ;
169
- }
170
-
171
146
let const_ = Const :: from_ty_const ( len, self . tcx . types . usize , self . tcx ) ;
172
- let constant = ConstOperand { span : source_info . span , const_, user_ty : None } ;
147
+ let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
173
148
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
174
149
}
175
150
}
176
151
}
177
152
178
153
/// Transform `Aggregate(RawPtr, [p, ()])` ==> `Cast(PtrToPtr, p)`.
179
- fn simplify_ptr_aggregate ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
154
+ fn simplify_ptr_aggregate ( & self , rvalue : & mut Rvalue < ' tcx > ) {
180
155
if let Rvalue :: Aggregate ( box AggregateKind :: RawPtr ( pointee_ty, mutability) , fields) = rvalue
181
156
{
182
157
let meta_ty = fields. raw [ 1 ] . ty ( self . local_decls , self . tcx ) ;
183
158
if meta_ty. is_unit ( ) {
184
159
// The mutable borrows we're holding prevent printing `rvalue` here
185
- if !self . should_simplify_custom (
186
- source_info,
187
- "Aggregate::RawPtr" ,
188
- ( & pointee_ty, * mutability, & fields) ,
189
- ) {
190
- return ;
191
- }
192
-
193
160
let mut fields = std:: mem:: take ( fields) ;
194
161
let _meta = fields. pop ( ) . unwrap ( ) ;
195
162
let data = fields. pop ( ) . unwrap ( ) ;
@@ -199,10 +166,10 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
199
166
}
200
167
}
201
168
202
- fn simplify_ub_check ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
169
+ fn simplify_ub_check ( & self , rvalue : & mut Rvalue < ' tcx > ) {
203
170
if let Rvalue :: NullaryOp ( NullOp :: UbChecks , _) = * rvalue {
204
171
let const_ = Const :: from_bool ( self . tcx , self . tcx . sess . ub_checks ( ) ) ;
205
- let constant = ConstOperand { span : source_info . span , const_, user_ty : None } ;
172
+ let constant = ConstOperand { span : DUMMY_SP , const_, user_ty : None } ;
206
173
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
207
174
}
208
175
}
@@ -290,16 +257,6 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
290
257
return ;
291
258
}
292
259
293
- if !self . tcx . consider_optimizing ( || {
294
- format ! (
295
- "InstSimplify - Call: {:?} SourceInfo: {:?}" ,
296
- ( fn_def_id, fn_args) ,
297
- terminator. source_info
298
- )
299
- } ) {
300
- return ;
301
- }
302
-
303
260
let Ok ( [ arg] ) = take_array ( args) else { return } ;
304
261
let Some ( arg_place) = arg. node . place ( ) else { return } ;
305
262
0 commit comments