@@ -383,9 +383,6 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
383
383
384
384
// Vectors, even for non-power-of-two sizes, have the same layout as
385
385
// 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.
389
386
if let FieldsShape :: Array { count, .. } = self . layout . fields ( )
390
387
&& count. is_power_of_two ( )
391
388
&& let element = self . field ( cx, 0 )
@@ -396,8 +393,19 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
396
393
// up suppressing vectorization as it introduces shifts when it
397
394
// extracts all the individual values.
398
395
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
+ }
401
409
}
402
410
403
411
// FIXME: The above only handled integer arrays; surely more things
0 commit comments