about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-23 10:01:48 +0000
committerbors <bors@rust-lang.org>2022-11-23 10:01:48 +0000
commit4e0d0d757e2f1b61ec809420b006545a9f8974c0 (patch)
tree2bc6f5a32e16c8b7dd42ba0b3f963da53fceed23 /compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
parent3f2b2eee8f46f2252d2919d7a57bf3068d7df285 (diff)
parentc1f392dbc09d9fef086f84bbcbecebc0cde8df81 (diff)
downloadrust-4e0d0d757e2f1b61ec809420b006545a9f8974c0.tar.gz
rust-4e0d0d757e2f1b61ec809420b006545a9f8974c0.zip
Auto merge of #102750 - the8472:opt-field-order, r=wesleywiser
optimize field ordering by grouping m*2^n-sized fields with equivalently aligned ones

```rust
use std::ptr::addr_of;
use std::mem;

struct Foo {
    word: u32,
    byte: u8,
    ary: [u8; 4]
}

fn main() {
    let foo: Foo = unsafe { mem::zeroed() };

    println!("base: {:p}\nword: {:p}\nbyte: {:p}\nary:  {:p}", &foo, addr_of!(foo.word), addr_of!(foo.byte), addr_of!(foo.ary));
}
```

prints

```
base: 0x7fffc1a8a668
word: 0x7fffc1a8a668
byte: 0x7fffc1a8a66c
ary:  0x7fffc1a8a66d
```

I.e. the `u8` in the middle causes the array to sit at an odd offset, which might prevent optimizations, especially on architectures where unaligned loads are costly.

Note that this will make field ordering niche-dependent, i.e. a `Bar<T>` with `T=char` and `T=u32` may result in different field order, this may break some code that makes invalid assumptions about `repr(Rust)` types.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
0 files changed, 0 insertions, 0 deletions