@@ -1527,6 +1527,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
15271527 }
15281528 }
15291529
1530+ #[ instrument( level = "trace" , skip( self ) , ret) ]
15301531 fn simplify_cast (
15311532 & mut self ,
15321533 initial_kind : & mut CastKind ,
@@ -1582,6 +1583,30 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
15821583 }
15831584 }
15841585
1586+ // Field-Access-then-Transmute can just transmute the original value,
1587+ // so long as the bytes of a value from only from a single field.
1588+ if let Transmute = kind
1589+ && let Value :: Projection ( field_value, ProjectionElem :: Field ( field_idx, ( ) ) ) =
1590+ self . get ( value)
1591+ {
1592+ if let Value :: Projection (
1593+ _downcast_value,
1594+ ProjectionElem :: Downcast ( _, _variant_idx) ,
1595+ ) = self . get ( field_value)
1596+ {
1597+ } else if let Some ( ( f_idx, field_ty) ) =
1598+ self . value_is_all_in_one_field ( self . ty ( field_value) , FIRST_VARIANT )
1599+ {
1600+ assert_eq ! ( field_idx, f_idx, "{from} -> {field_ty}" ) ;
1601+ from = self . ty ( field_value) ;
1602+ value = field_value;
1603+ was_updated_this_iteration = true ;
1604+ if field_ty == to {
1605+ return Some ( value) ;
1606+ }
1607+ }
1608+ }
1609+
15851610 // Aggregate-then-Transmute can just transmute the original field value,
15861611 // so long as the bytes of a value from only from a single field.
15871612 if let Transmute = kind
0 commit comments