Skip to content

Commit c7e8880

Browse files
committed
Retry with the homogeneous aggregate concept
1 parent 0c1451c commit c7e8880

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

compiler/rustc_middle/src/ty/layout.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, Variant
1414
use rustc_span::symbol::Symbol;
1515
use rustc_span::{Span, DUMMY_SP};
1616
use rustc_target::abi::call::{
17-
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
17+
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, HomogeneousAggregate, PassMode,
18+
Reg, RegKind,
1819
};
1920
use rustc_target::abi::*;
2021
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
@@ -3340,17 +3341,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33403341
Ok(self.tcx.arena.alloc(fn_abi))
33413342
}
33423343

3343-
/// Small heuristic for determining if layout has any float primitive
3344-
fn has_all_float(&self, layout: &'_ TyAndLayout<'tcx>) -> bool {
3345-
match layout.abi {
3346-
Abi::Uninhabited | Abi::Vector { .. } => false,
3347-
Abi::Scalar(scalar) => matches!(scalar.primitive(), Primitive::F32 | Primitive::F64),
3348-
Abi::ScalarPair(..) | Abi::Aggregate { .. } => {
3349-
(0..layout.fields.count()).all(|i| self.has_all_float(&layout.field(self, i)))
3350-
}
3351-
}
3352-
}
3353-
33543344
fn fn_abi_adjust_for_abi(
33553345
&self,
33563346
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
@@ -3381,12 +3371,19 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33813371

33823372
if arg.layout.is_unsized() || size > max_by_val_size {
33833373
arg.make_indirect();
3384-
} else if size > ptr_size && self.has_all_float(&arg.layout) {
3374+
} else if let Ok(HomogeneousAggregate::Homogeneous(Reg {
3375+
kind: RegKind::Float,
3376+
..
3377+
})) = arg.layout.homogeneous_aggregate(self)
3378+
{
33853379
// We don't want to aggregate floats as an aggregates of Integer
3386-
// because this will hurt the generated assembly (#93490) but as an
3387-
// optimization we want to pass homogeneous aggregate of floats
3388-
// greater than pointer size as indirect.
3389-
arg.make_indirect();
3380+
// because this will hurt the generated assembly (#93490)
3381+
//
3382+
// As an optimization we want to pass homogeneous aggregate of floats
3383+
// greater than pointer size as indirect
3384+
if size > ptr_size {
3385+
arg.make_indirect();
3386+
}
33903387
} else {
33913388
// We want to pass small aggregates as immediates, but using
33923389
// a LLVM aggregate type for this leads to bad optimizations,

src/test/codegen/homogeneous-floats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Foo {
1313
bar4: f32,
1414
}
1515

16-
// CHECK: define i64 @array_f32x2(i64 %0, i64 %1)
16+
// CHECK: define [2 x float] @array_f32x2([2 x float] %0, [2 x float] %1)
1717
#[no_mangle]
1818
pub fn array_f32x2(a: [f32; 2], b: [f32; 2]) -> [f32; 2] {
1919
todo!()

0 commit comments

Comments
 (0)