@@ -383,9 +383,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
383383
384384 // Vectors, even for non-power-of-two sizes, have the same layout as
385385 // arrays but don't count as aggregate types
386- // While LLVM theoretically supports non-power-of-two sizes, and they
387- // often work fine, sometimes x86-isel deals with them horribly
388- // (see #115212) so for now only use power-of-two ones.
389386 if let FieldsShape :: Array { count, .. } = self . layout . fields ( )
390387 && count. is_power_of_two ( )
391388 && let element = self . field ( cx, 0 )
@@ -396,8 +393,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
396393 // up suppressing vectorization as it introduces shifts when it
397394 // extracts all the individual values.
398395
399- let ety = element. llvm_type ( cx) ;
400- return Some ( cx. type_vector ( ety, * count) ) ;
396+ if * count <= 2 {
397+ // For short arrays, use LLVM's array type which it will unpack
398+ // out in optimizations to a scalar or pair of scalars.
399+ // (Having types like `<1 x u8>` is silly.)
400+ let ety = element. llvm_type ( cx) ;
401+ return Some ( cx. type_array ( ety, * count) ) ;
402+ } else if count. is_power_of_two ( ) {
403+ // While LLVM theoretically supports non-power-of-two sizes, and they
404+ // often work fine, sometimes x86-isel deals with them horribly
405+ // (see #115212) so for now only use power-of-two ones.
406+ let ety = element. llvm_type ( cx) ;
407+ return Some ( cx. type_vector ( ety, * count) ) ;
408+ }
401409 }
402410
403411 // FIXME: The above only handled integer arrays; surely more things
0 commit comments