@@ -1495,6 +1495,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
14951495 }
14961496 }
14971497
1498+ #[ instrument( level = "trace" , skip( self ) , ret) ]
14981499 fn simplify_cast (
14991500 & mut self ,
15001501 initial_kind : & mut CastKind ,
@@ -1550,6 +1551,42 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
15501551 }
15511552 }
15521553
1554+ // Field-Access-then-Transmute can just transmute the original value,
1555+ // so long as the bytes of a value from only from a single field.
1556+ if let Transmute = kind
1557+ && let Value :: Projection ( field_value, ProjectionElem :: Field ( field_idx, ( ) ) ) =
1558+ self . get ( value)
1559+ {
1560+ if let Value :: Projection (
1561+ downcast_value,
1562+ ProjectionElem :: Downcast ( _, _variant_idx) ,
1563+ ) = self . get ( field_value)
1564+ {
1565+ let downcast_ty = self . ty ( downcast_value) ;
1566+ if let Ok ( downcast_layout) = self . ecx . layout_of ( downcast_ty)
1567+ && let Ok ( projected_layout) = self . ecx . layout_of ( from)
1568+ && downcast_layout. size == projected_layout. size
1569+ {
1570+ from = downcast_ty;
1571+ value = downcast_value;
1572+ was_updated_this_iteration = true ;
1573+ if projected_layout. ty == to {
1574+ return Some ( value) ;
1575+ }
1576+ }
1577+ } else if let Some ( ( f_idx, field_ty) ) =
1578+ self . value_is_all_in_one_field ( self . ty ( field_value) , FIRST_VARIANT )
1579+ {
1580+ assert_eq ! ( field_idx, f_idx, "{from} -> {field_ty}" ) ;
1581+ from = self . ty ( field_value) ;
1582+ value = field_value;
1583+ was_updated_this_iteration = true ;
1584+ if field_ty == to {
1585+ return Some ( value) ;
1586+ }
1587+ }
1588+ }
1589+
15531590 // Aggregate-then-Transmute can just transmute the original field value,
15541591 // so long as the bytes of a value from only from a single field.
15551592 if let Transmute = kind
0 commit comments