@@ -541,7 +541,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
541541 // type whose creation requires no write. E.g. a generator whose initial state
542542 // consists solely of uninitialized memory (so it doesn't capture any locals).
543543 let value = self . get_const ( place) ?;
544- if !self . should_const_prop ( & value) {
544+ if !self . tcx . consider_optimizing ( || format ! ( "ConstantPropagation - { value:?}" ) ) {
545545 return None ;
546546 }
547547 trace ! ( "replacing {:?} with {:?}" , place, value) ;
@@ -551,10 +551,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
551551
552552 let Right ( imm) = imm else { return None } ;
553553 match * imm {
554- interpret :: Immediate :: Scalar ( scalar) => {
554+ Immediate :: Scalar ( scalar) if scalar . try_to_int ( ) . is_ok ( ) => {
555555 Some ( self . operand_from_scalar ( scalar, value. layout . ty ) )
556556 }
557- Immediate :: ScalarPair ( .. ) => {
557+ Immediate :: ScalarPair ( l , r ) if l . try_to_int ( ) . is_ok ( ) && r . try_to_int ( ) . is_ok ( ) => {
558558 let alloc = self
559559 . ecx
560560 . intern_with_temp_alloc ( value. layout , |ecx, dest| {
@@ -578,21 +578,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
578578 }
579579 }
580580
581- /// Returns `true` if and only if this `op` should be const-propagated into.
582- fn should_const_prop ( & mut self , op : & OpTy < ' tcx > ) -> bool {
583- if !self . tcx . consider_optimizing ( || format ! ( "ConstantPropagation - OpTy: {:?}" , op) ) {
584- return false ;
585- }
586-
587- match * * op {
588- interpret:: Operand :: Immediate ( Immediate :: Scalar ( s) ) => s. try_to_int ( ) . is_ok ( ) ,
589- interpret:: Operand :: Immediate ( Immediate :: ScalarPair ( l, r) ) => {
590- l. try_to_int ( ) . is_ok ( ) && r. try_to_int ( ) . is_ok ( )
591- }
592- _ => false ,
593- }
594- }
595-
596581 fn ensure_not_propagated ( & self , local : Local ) {
597582 if cfg ! ( debug_assertions) {
598583 assert ! (
@@ -744,8 +729,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
744729 ) -> Option < PlaceElem < ' tcx > > {
745730 if let PlaceElem :: Index ( local) = elem
746731 && let Some ( value) = self . get_const ( local. into ( ) )
747- && self . should_const_prop ( & value)
748- && let interpret:: Operand :: Immediate ( interpret:: Immediate :: Scalar ( scalar) ) = * value
732+ && let interpret:: Operand :: Immediate ( Immediate :: Scalar ( scalar) ) = * value
749733 && let Ok ( offset) = scalar. to_target_usize ( & self . tcx )
750734 && let Some ( min_length) = offset. checked_add ( 1 )
751735 {
0 commit comments