Skip to content

Commit 3aeb61b

Browse files
committed
Do not over-optimize the abi layout
1 parent 7cc28c1 commit 3aeb61b

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

compiler/rustc_middle/src/ty/layout.rs

+13-18
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::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,17 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
31823182
}
31833183

31843184
match arg.layout.abi {
3185-
Abi::Aggregate { .. } => {}
3185+
Abi::Aggregate { .. } => {
3186+
// Pass and return structures up to 2 pointers in size by value,
3187+
// matching `ScalarPair`. LLVM will usually pass these in 2 registers
3188+
// which is more efficient than by-ref.
3189+
let max_by_val_size = Pointer.size(self) * 2;
3190+
let size = arg.layout.size;
3191+
3192+
if arg.layout.is_unsized() || size >= max_by_val_size {
3193+
arg.make_indirect();
3194+
}
3195+
}
31863196

31873197
// This is a fun case! The gist of what this is doing is
31883198
// that we want callers and callees to always agree on the
@@ -3208,24 +3218,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
32083218
&& self.tcx.sess.target.simd_types_indirect =>
32093219
{
32103220
arg.make_indirect();
3211-
return;
32123221
}
32133222

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 });
3223+
_ => {}
32293224
}
32303225
};
32313226
fixup(&mut fn_abi.ret);

0 commit comments

Comments
 (0)