Skip to content

Commit a3450d0

Browse files
committed
group fields based on largest power of two dividing its size
1 parent 9f0cb56 commit a3450d0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,10 @@ fn univariant_uninterned<'tcx>(
140140
let optimizing = &mut inverse_memory_index[..end];
141141
let effective_field_align = |f: &TyAndLayout<'_>| {
142142
if let Some(pack) = pack {
143-
f.align.abi.min(pack)
144-
} else if f.size.bytes().is_power_of_two() && f.size.bytes() >= f.align.abi.bytes() {
145-
// Try to put fields which have a 2^n size and smaller alignment together with
146-
// fields that have an alignment matching that size.
147-
// E.g. group [u8; 4] with u32 fields
148-
Align::from_bytes(f.align.abi.bytes()).unwrap_or(f.align.abi)
143+
f.align.abi.min(pack).bytes()
149144
} else {
150-
f.align.abi
145+
// group [u8; 4] with align-4 or [u8; 6] with align-2 fields
146+
f.align.abi.bytes().max(f.size.bytes()).trailing_zeros() as u64
151147
}
152148
};
153149

0 commit comments

Comments
 (0)