Skip to content

Commit 9ed05ed

Browse files
committed
Use simpler heuristic for determining if a layout only floats
1 parent ec16a32 commit 9ed05ed

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ 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, HomogeneousAggregate, PassMode,
18-
Reg, RegKind,
17+
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
1918
};
2019
use rustc_target::abi::*;
2120
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
@@ -3341,6 +3340,17 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33413340
Ok(self.tcx.arena.alloc(fn_abi))
33423341
}
33433342

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+
33443354
fn fn_abi_adjust_for_abi(
33453355
&self,
33463356
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
@@ -3370,11 +3380,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33703380

33713381
if arg.layout.is_unsized() || size > max_by_val_size {
33723382
arg.make_indirect();
3373-
} else if let Ok(HomogeneousAggregate::Homogeneous(Reg {
3374-
kind: RegKind::Float,
3375-
..
3376-
})) = arg.layout.homogeneous_aggregate(self)
3377-
{
3383+
} else if unlikely!(self.has_all_float(&arg.layout)) {
33783384
// We don't want to aggregate floats as an aggregates of Integer
33793385
// because this will hurt the generated assembly (#93490)
33803386
//

0 commit comments

Comments
 (0)