Skip to content

Commit e6e2f15

Browse files
committed
Lower the threshold for indirect aggregate and remove cast to integer
1 parent 3e21768 commit e6e2f15

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_session::{config::OptLevel, DataTypeKind, FieldInfo, SizeKind, Variant
1313
use rustc_span::symbol::{Ident, Symbol};
1414
use rustc_span::{Span, DUMMY_SP};
1515
use rustc_target::abi::call::{
16-
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
16+
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode,
1717
};
1818
use rustc_target::abi::*;
1919
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
@@ -3182,7 +3182,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
31823182
}
31833183

31843184
match arg.layout.abi {
3185-
Abi::Aggregate { .. } => {}
3185+
Abi::Aggregate { .. } => {
3186+
let max_by_val_size = Pointer.size(self);
3187+
let size = arg.layout.size;
3188+
3189+
if arg.layout.is_unsized() || size > max_by_val_size {
3190+
arg.make_indirect();
3191+
}
3192+
}
31863193

31873194
// This is a fun case! The gist of what this is doing is
31883195
// that we want callers and callees to always agree on the
@@ -3208,24 +3215,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
32083215
&& self.tcx.sess.target.simd_types_indirect =>
32093216
{
32103217
arg.make_indirect();
3211-
return;
32123218
}
3213-
3214-
_ => return,
3215-
}
3216-
3217-
// Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
3218-
// LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
3219-
let max_by_val_size = Pointer.size(self) * 2;
3220-
let size = arg.layout.size;
3221-
3222-
if arg.layout.is_unsized() || size > max_by_val_size {
3223-
arg.make_indirect();
3224-
} else {
3225-
// We want to pass small aggregates as immediates, but using
3226-
// a LLVM aggregate type for this leads to bad optimizations,
3227-
// so we pick an appropriately sized integer type instead.
3228-
arg.cast_to(Reg { kind: RegKind::Integer, size });
3219+
_ => {}
32293220
}
32303221
};
32313222
fixup(&mut fn_abi.ret);

0 commit comments

Comments
 (0)