@@ -7,6 +7,7 @@ use rustc_middle::mir::*;
77use rustc_middle:: ty:: layout:: ValidityRequirement ;
88use rustc_middle:: ty:: { self , GenericArgsRef , ParamEnv , Ty , TyCtxt } ;
99use rustc_span:: symbol:: Symbol ;
10+ use rustc_span:: DUMMY_SP ;
1011use rustc_target:: abi:: FieldIdx ;
1112
1213pub struct InstSimplify ;
@@ -26,10 +27,10 @@ impl<'tcx> MirPass<'tcx> for InstSimplify {
2627 for statement in block. statements . iter_mut ( ) {
2728 match statement. kind {
2829 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) ;
3334 }
3435 _ => { }
3536 }
@@ -55,14 +56,8 @@ struct InstSimplifyContext<'tcx, 'a> {
5556}
5657
5758impl < ' 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-
6459 /// 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 > ) {
6661 match rvalue {
6762 Rvalue :: BinaryOp ( op @ ( BinOp :: Eq | BinOp :: Ne ) , box ( a, b) ) => {
6863 let new = match ( op, self . try_eval_bool ( a) , self . try_eval_bool ( b) ) {
@@ -93,7 +88,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
9388 _ => None ,
9489 } ;
9590
96- if let Some ( new) = new && self . should_simplify ( source_info , rvalue ) {
91+ if let Some ( new) = new {
9792 * rvalue = new;
9893 }
9994 }
@@ -108,17 +103,13 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
108103 }
109104
110105 /// 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 > ) {
112107 if let Rvalue :: Ref ( _, _, place) = rvalue {
113108 if let Some ( ( base, ProjectionElem :: Deref ) ) = place. as_ref ( ) . last_projection ( ) {
114109 if rvalue. ty ( self . local_decls , self . tcx ) != base. ty ( self . local_decls , self . tcx ) . ty {
115110 return ;
116111 }
117112
118- if !self . should_simplify ( source_info, rvalue) {
119- return ;
120- }
121-
122113 * rvalue = Rvalue :: Use ( Operand :: Copy ( Place {
123114 local : base. local ,
124115 projection : self . tcx . mk_place_elems ( base. projection ) ,
@@ -128,22 +119,18 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
128119 }
129120
130121 /// 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 > ) {
132123 if let Rvalue :: Len ( ref place) = * rvalue {
133124 let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
134125 if let ty:: Array ( _, len) = * place_ty. kind ( ) {
135- if !self . should_simplify ( source_info, rvalue) {
136- return ;
137- }
138-
139126 let literal = ConstantKind :: from_ty_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 } ;
141128 * rvalue = Rvalue :: Use ( Operand :: Constant ( Box :: new ( constant) ) ) ;
142129 }
143130 }
144131 }
145132
146- fn simplify_cast ( & self , _source_info : & SourceInfo , rvalue : & mut Rvalue < ' tcx > ) {
133+ fn simplify_cast ( & self , rvalue : & mut Rvalue < ' tcx > ) {
147134 if let Rvalue :: Cast ( kind, operand, cast_ty) = rvalue {
148135 let operand_ty = operand. ty ( self . local_decls , self . tcx ) ;
149136 if operand_ty == * cast_ty {
@@ -223,16 +210,6 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
223210 return ;
224211 }
225212
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-
236213 let Some ( arg_place) = args. pop ( ) . unwrap ( ) . place ( ) else { return } ;
237214
238215 statements. push ( Statement {
0 commit comments