Skip to content

Commit 374bc27

Browse files
committed
Simplify the code of fixup by making it's code flow more natural
1 parent 4045ce6 commit 374bc27

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,7 +3360,22 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33603360
}
33613361

33623362
match arg.layout.abi {
3363-
Abi::Aggregate { .. } => {}
3363+
Abi::Aggregate { .. } => {
3364+
// Pass and return structures up to 2 pointers in size by value,
3365+
// matching `ScalarPair`. LLVM will usually pass these in 2 registers
3366+
// which is more efficient than by-ref.
3367+
let max_by_val_size = Pointer.size(self) * 2;
3368+
let size = arg.layout.size;
3369+
3370+
if arg.layout.is_unsized() || size > max_by_val_size {
3371+
arg.make_indirect();
3372+
} else {
3373+
// We want to pass small aggregates as immediates, but using
3374+
// a LLVM aggregate type for this leads to bad optimizations,
3375+
// so we pick an appropriately sized integer type instead.
3376+
arg.cast_to(Reg { kind: RegKind::Integer, size });
3377+
}
3378+
}
33643379

33653380
// This is a fun case! The gist of what this is doing is
33663381
// that we want callers and callees to always agree on the
@@ -3386,20 +3401,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
33863401
&& self.tcx.sess.target.simd_types_indirect =>
33873402
{
33883403
arg.make_indirect();
3389-
return;
33903404
}
33913405

3392-
_ => return,
3393-
}
3394-
3395-
let size = arg.layout.size;
3396-
if arg.layout.is_unsized() || size > Pointer.size(self) {
3397-
arg.make_indirect();
3398-
} else {
3399-
// We want to pass small aggregates as immediates, but using
3400-
// a LLVM aggregate type for this leads to bad optimizations,
3401-
// so we pick an appropriately sized integer type instead.
3402-
arg.cast_to(Reg { kind: RegKind::Integer, size });
3406+
_ => {},
34033407
}
34043408
};
34053409
fixup(&mut fn_abi.ret);

0 commit comments

Comments
 (0)