Skip to content

Commit

Permalink
Avoid using load/stores on first class aggregates
Browse files Browse the repository at this point in the history
LLVM usually prefers using memcpys over direct loads/store of first
class aggregates. The check in type_is_immediate to mark certain small
structs was originally part of the code to handle such immediates in
function arguments, and it had a counterpart in load_ty/store_ty to
actually convert small aggregates to integers.

But since then, the ABI handling has been refactored and takes care of
converting small aggregates to integers. During that refactoring, the
code to handle small aggregates in load_ty/store_ty has been removed,
and so we accidentally started using loads/stores on FCA values.

Since type_is_immediate() is no longer responsible for ABI-related
conversions, and using a memcpy even for small aggregates is usually
better than performing a FCA load/store, we can remove that code part
and only handle simple types as immediates there.

This integrates PR #38906 onto this branch.

Fixes #38906.
  • Loading branch information
dotdash authored and Mark-Simulacrum committed Jan 13, 2017
1 parent e393046 commit 43cf5b9
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/librustc_trans/common.rs
Expand Up @@ -67,8 +67,7 @@ pub fn type_is_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
Layout::UntaggedUnion { .. } |
Layout::RawNullablePointer { .. } |
Layout::StructWrappedNullablePointer { .. } => {
let dl = &ccx.tcx().data_layout;
!layout.is_unsized() && layout.size(dl) <= dl.pointer_size
!layout.is_unsized() && layout.size(&ccx.tcx().data_layout).bytes() == 0
}
}
}
Expand Down

0 comments on commit 43cf5b9

Please sign in to comment.