@@ -1494,6 +1494,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
14941494 }
14951495 }
14961496
1497+ #[ instrument( level = "trace" , skip( self ) , ret) ]
14971498 fn simplify_cast (
14981499 & mut self ,
14991500 initial_kind : & mut CastKind ,
@@ -1549,6 +1550,30 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
15491550 }
15501551 }
15511552
1553+ // Field-Access-then-Transmute can just transmute the original value,
1554+ // so long as the bytes of a value from only from a single field.
1555+ if let Transmute = kind
1556+ && let Value :: Projection ( field_value, ProjectionElem :: Field ( field_idx, ( ) ) ) =
1557+ self . get ( value)
1558+ {
1559+ if let Value :: Projection (
1560+ _downcast_value,
1561+ ProjectionElem :: Downcast ( _, _variant_idx) ,
1562+ ) = self . get ( field_value)
1563+ {
1564+ } else if let Some ( ( f_idx, field_ty) ) =
1565+ self . value_is_all_in_one_field ( self . ty ( field_value) , FIRST_VARIANT )
1566+ {
1567+ assert_eq ! ( field_idx, f_idx, "{from} -> {field_ty}" ) ;
1568+ from = self . ty ( field_value) ;
1569+ value = field_value;
1570+ was_updated_this_iteration = true ;
1571+ if field_ty == to {
1572+ return Some ( value) ;
1573+ }
1574+ }
1575+ }
1576+
15521577 // Aggregate-then-Transmute can just transmute the original field value,
15531578 // so long as the bytes of a value from only from a single field.
15541579 if let Transmute = kind
0 commit comments