@@ -7,6 +7,7 @@ use rustc_middle::mir::*;
7
7
use rustc_middle:: ty:: layout:: ValidityRequirement ;
8
8
use rustc_middle:: ty:: { self , GenericArgsRef , ParamEnv , Ty , TyCtxt } ;
9
9
use rustc_span:: symbol:: Symbol ;
10
+ use rustc_span:: DUMMY_SP ;
10
11
use rustc_target:: abi:: FieldIdx ;
11
12
12
13
pub struct InstSimplify ;
@@ -26,10 +27,10 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
26
27
for statement in block. statements . iter_mut ( ) {
27
28
match statement. kind {
28
29
StatementKind :: Assign ( box ( _place, ref mut rvalue) ) => {
29
- ctx. simplify_bool_cmp ( & statement . source_info , rvalue) ;
30
- ctx. simplify_ref_deref ( & statement . source_info , rvalue) ;
31
- ctx. simplify_len ( & statement . source_info , rvalue) ;
32
- ctx. simplify_cast ( & statement . source_info , rvalue) ;
30
+ ctx. simplify_bool_cmp ( rvalue) ;
31
+ ctx. simplify_ref_deref ( rvalue) ;
32
+ ctx. simplify_len ( rvalue) ;
33
+ ctx. simplify_cast ( rvalue) ;
33
34
}
34
35
_ => { }
35
36
}
@@ -55,14 +56,8 @@ struct InstSimplifyContext<'tcx, 'a> {
55
56
}
56
57
57
58
impl < ' tcx > InstSimplifyContext < ' tcx , ' _ > {
58
- fn should_simplify ( & self , source_info : & SourceInfo , rvalue : & Rvalue < ' tcx > ) -> bool {
59
- self . tcx . consider_optimizing ( || {
60
- format ! ( "InstSimplify - Rvalue: {rvalue:?} SourceInfo: {source_info:?}" )
61
- } )
62
- }
63
-
64
59
/// Transform boolean comparisons into logical operations.
65
- fn simplify_bool_cmp ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
60
+ fn simplify_bool_cmp ( & self , rvalue : & mut Rvalue < ' tcx > ) {
66
61
match rvalue {
67
62
Rvalue :: BinaryOp ( op @ ( BinOp :: Eq | BinOp :: Ne ) , box ( a, b) ) => {
68
63
let new = match ( op, self . try_eval_bool ( a) , self . try_eval_bool ( b) ) {
@@ -93,7 +88,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
93
88
_ => None ,
94
89
} ;
95
90
96
- if let Some ( new) = new && self . should_simplify ( source_info , rvalue ) {
91
+ if let Some ( new) = new {
97
92
* rvalue = new;
98
93
}
99
94
}
@@ -108,17 +103,13 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
108
103
}
109
104
110
105
/// Transform "&(*a)" ==> "a".
111
- fn simplify_ref_deref ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
106
+ fn simplify_ref_deref ( & self , rvalue : & mut Rvalue < ' tcx > ) {
112
107
if let Rvalue :: Ref ( _, _, place) = rvalue {
113
108
if let Some ( ( base, ProjectionElem :: Deref ) ) = place. as_ref ( ) . last_projection ( ) {
114
109
if rvalue. ty ( self . local_decls , self . tcx ) != base. ty ( self . local_decls , self . tcx ) . ty {
115
110
return ;
116
111
}
117
112
118
- if !self . should_simplify ( source_info, rvalue) {
119
- return ;
120
- }
121
-
122
113
* rvalue = Rvalue :: Use ( Operand :: Copy ( Place {
123
114
local : base. local ,
124
115
projection : self . tcx . mk_place_elems ( base. projection ) ,
@@ -128,22 +119,18 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
128
119
}
129
120
130
121
/// Transform "Len([_; N])" ==> "N".
131
- fn simplify_len ( & self , source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
122
+ fn simplify_len ( & self , rvalue : & mut Rvalue < ' tcx > ) {
132
123
if let Rvalue :: Len ( ref place) = * rvalue {
133
124
let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
134
125
if let ty:: Array ( _, len) = * place_ty. kind ( ) {
135
- if !self . should_simplify ( source_info, rvalue) {
136
- return ;
137
- }
138
-
139
126
let literal = ConstantKind :: from_const ( len, self . tcx ) ;
140
- let constant = Constant { span : source_info . span , literal, user_ty : None } ;
127
+ let constant = Constant { span : DUMMY_SP , literal, user_ty : None } ;
141
128
* rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
142
129
}
143
130
}
144
131
}
145
132
146
- fn simplify_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
133
+ fn simplify_cast ( & self , rvalue : & mut Rvalue < ' tcx > ) {
147
134
if let Rvalue :: Cast ( kind, operand, cast_ty) = rvalue {
148
135
let operand_ty = operand. ty ( self . local_decls , self . tcx ) ;
149
136
if operand_ty == * cast_ty {
@@ -223,16 +210,6 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
223
210
return ;
224
211
}
225
212
226
- if !self . tcx . consider_optimizing ( || {
227
- format ! (
228
- "InstSimplify - Call: {:?} SourceInfo: {:?}" ,
229
- ( fn_def_id, fn_args) ,
230
- terminator. source_info
231
- )
232
- } ) {
233
- return ;
234
- }
235
-
236
213
let Some ( arg_place) = args. pop ( ) . unwrap ( ) . place ( ) else { return } ;
237
214
238
215
statements. push ( Statement {
0 commit comments