@@ -713,6 +713,8 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
713
713
ty:: Adt ( adt, _) if adt. is_enum ( ) => adt,
714
714
_ => return StatementEquality :: NotEqual ,
715
715
} ;
716
+ // We need to make sure that the switch value that targets the bb with
717
+ // SetDiscriminant is the same as the variant discriminant.
716
718
let variant_discr = adt. discriminant_for_variant ( self . tcx , * variant_index) . val ;
717
719
if variant_discr != switch_value {
718
720
trace ! (
@@ -750,20 +752,28 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
750
752
(
751
753
StatementKind :: Assign ( box ( _, rhs) ) ,
752
754
StatementKind :: SetDiscriminant { place, variant_index } ,
753
- )
754
- // we need to make sure that the switch value that targets the bb with SetDiscriminant (y), is the same as the variant index
755
- if y_target_and_value. value . is_some ( ) => {
755
+ ) if y_target_and_value. value . is_some ( ) => {
756
756
// choose basic block of x, as that has the assign
757
- helper ( rhs, place, variant_index, y_target_and_value. value . unwrap ( ) , x_target_and_value. target )
757
+ helper (
758
+ rhs,
759
+ place,
760
+ variant_index,
761
+ y_target_and_value. value . unwrap ( ) ,
762
+ x_target_and_value. target ,
763
+ )
758
764
}
759
765
(
760
766
StatementKind :: SetDiscriminant { place, variant_index } ,
761
767
StatementKind :: Assign ( box ( _, rhs) ) ,
762
- )
763
- // we need to make sure that the switch value that targets the bb with SetDiscriminant (x), is the same as the variant index
764
- if x_target_and_value. value . is_some ( ) => {
768
+ ) if x_target_and_value. value . is_some ( ) => {
765
769
// choose basic block of y, as that has the assign
766
- helper ( rhs, place, variant_index, x_target_and_value. value . unwrap ( ) , y_target_and_value. target )
770
+ helper (
771
+ rhs,
772
+ place,
773
+ variant_index,
774
+ x_target_and_value. value . unwrap ( ) ,
775
+ y_target_and_value. target ,
776
+ )
767
777
}
768
778
_ => {
769
779
trace ! ( "NO: statements `{:?}` and `{:?}` not considered equal" , x, y) ;
0 commit comments