@@ -541,7 +541,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
541
541
// type whose creation requires no write. E.g. a generator whose initial state
542
542
// consists solely of uninitialized memory (so it doesn't capture any locals).
543
543
let value = self . get_const ( place) ?;
544
- if !self . should_const_prop ( & value) {
544
+ if !self . tcx . consider_optimizing ( || format ! ( "ConstantPropagation - { value:?}" ) ) {
545
545
return None ;
546
546
}
547
547
trace ! ( "replacing {:?} with {:?}" , place, value) ;
@@ -551,10 +551,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
551
551
552
552
let Right ( imm) = imm else { return None } ;
553
553
match * imm {
554
- interpret :: Immediate :: Scalar ( scalar) => {
554
+ Immediate :: Scalar ( scalar) if scalar . try_to_int ( ) . is_ok ( ) => {
555
555
Some ( self . operand_from_scalar ( scalar, value. layout . ty ) )
556
556
}
557
- Immediate :: ScalarPair ( .. ) => {
557
+ Immediate :: ScalarPair ( l , r ) if l . try_to_int ( ) . is_ok ( ) && r . try_to_int ( ) . is_ok ( ) => {
558
558
let alloc = self
559
559
. ecx
560
560
. intern_with_temp_alloc ( value. layout , |ecx, dest| {
@@ -578,21 +578,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
578
578
}
579
579
}
580
580
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
-
596
581
fn ensure_not_propagated ( & self , local : Local ) {
597
582
if cfg ! ( debug_assertions) {
598
583
assert ! (
@@ -744,8 +729,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
744
729
) -> Option < PlaceElem < ' tcx > > {
745
730
if let PlaceElem :: Index ( local) = elem
746
731
&& 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
749
733
&& let Ok ( offset) = scalar. to_target_usize ( & self . tcx )
750
734
&& let Some ( min_length) = offset. checked_add ( 1 )
751
735
{
0 commit comments