@@ -270,6 +270,16 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
270
270
TagEncoding :: Niche { untagged_variant, ref niche_variants, niche_start }
271
271
if is_niche_after_nonniche ( tag_scalar, niche_start, niche_variants, bx. cx ( ) ) =>
272
272
{
273
+ let ( niche_llty, tag) = match tag_scalar. primitive ( ) {
274
+ // Operations on u8/u16 directly result in some additional movzxs, pretend the tag
275
+ // is cast_to type (usize) instead.
276
+ // FIXUP this is very x86 specific assumption
277
+ Int ( Integer :: I8 | Integer :: I16 , _) => {
278
+ ( cast_to, bx. intcast ( tag, cast_to, false ) )
279
+ }
280
+ _ => ( niche_llty, tag) ,
281
+ } ;
282
+
273
283
let is_untagged = bx. icmp (
274
284
IntPredicate :: IntULT ,
275
285
tag,
@@ -593,8 +603,7 @@ fn round_up_const_value_to_alignment<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
593
603
594
604
/// Are all niche variants encoded in tag greater than the actual untagged tag values (so that we
595
605
/// can avoid the "relative discriminant" and we can simply `< niche_start` to ask whether it's
596
- /// untagged or not). Also check if last _variant_ value fits in the _tag_'s type.
597
- // Perhaps we can store this as flag in TagEncoding::Niche instead of recomputing?
606
+ /// untagged or not).
598
607
fn is_niche_after_nonniche (
599
608
tag : Scalar ,
600
609
niche_start : u128 ,
@@ -606,17 +615,5 @@ fn is_niche_after_nonniche(
606
615
return false ;
607
616
}
608
617
let n_variants = niche_variants. end ( ) . as_u32 ( ) - niche_variants. start ( ) . as_u32 ( ) ;
609
- match tag. primitive ( ) {
610
- Int ( int, _) => {
611
- if niche_start. checked_add ( n_variants as u128 ) != Some ( tag_range. end ) {
612
- return false ;
613
- }
614
- match int {
615
- Integer :: I8 if niche_variants. end ( ) . as_u32 ( ) > u8:: MAX as u32 => false ,
616
- Integer :: I16 if niche_variants. end ( ) . as_u32 ( ) > u16:: MAX as u32 => false ,
617
- _ => true ,
618
- }
619
- }
620
- _ => false ,
621
- }
618
+ niche_start. checked_add ( n_variants as u128 ) == Some ( tag_range. end )
622
619
}
0 commit comments