Repository: rust
Issue: Increased code size due to unnecessary memcpy libcall in `MaybeUninit::assume_init`
Labels: A-LLVM,I-slow,P-medium,T-compiler,regression-from-stable-to-stable,C-bug,I-heavy

After updating the compiler toolchain, I noticed that my binary got about 100 bytes larger. In my extremely size constrained environment, this is an increase of 5%. After a lot of minimizing, I tracked the main increase down to `MaybeUninit::assume_init`. It adds a new call to libc's `memcpy`. As far as I can tell, the code is moving the value on the stack a few bytes around, which is pointless (alignment should not be the issue here).

This might be related to #61011

### Code

[Godbolt link](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,selection:(endColumn:42,endLineNumber:17,positionColumn:42,positionLineNumber:17,selectionStartColumn:42,selectionStartLineNumber:17,startColumn:42,startLineNumber:17),source:'%23!!%5Bno_std%5D%0A%23!!%5Bno_main%5D%0A%23!!%5Bfeature(linkage)%5D%0A%0Ause+core::*%3B%0A%0A%23%5Bno_mangle%5D%0Aunsafe+fn+main()+-%3E+!!+%7B%0A%09let+flash:+%26FirmwareSig+%3D+%26*(0xe0000000+as+*const+FirmwareSig)%3B%0A%09let+mut+signature+%3D+mem::MaybeUninit::%3CFirmwareSig%3E::uninit()%3B%0A%0A%09memcpy(%0A%09%09(%26mut+signature)+as+*mut+mem::MaybeUninit::%3CFirmwareSig%3E+as+*mut+u8,%0A%09%09flash+as+*const+FirmwareSig+as+*const+u8,%0A%09%09mem::size_of::%3CFirmwareSig%3E(),%0A%09)%3B%0A%09let+signature+%3D+signature.assume_init()%3B%0A%0A%09let+pubkey_hash+%3D+sha256(%0A%09%09%26mem::transmute::%3C_,+%5Bu8%3B+mem::size_of::%3CPubkey%3E()%5D%3E(signature.pubkey)+as+%26%5Bu8%5D%0A%09)%3B%0A%0A%09if+%26pubkey_hash+%3D%3D+%26signature.pubkeys_hashes%5Bsignature.pubkey_id%5D+%7B%0A%09%7D+else+%7B%0A%09%09panic!!()%3B%0A%09%7D%0A%0A%09loop+%7B%7D%0A%7D%0A%0Atype+Hash+%3D+%5Bu8%3B+32%5D%3B%0Atype+Pubkey+%3D+%5B%5BHash%3B+2%5D%3B+256%5D%3B%0A%0A%23%5Brepr(C)%5D+%0Astruct+FirmwareSig+%7B%0A%09pubkey_id:+usize,%0A%09pubkey:+Pubkey,%0A%09pubkeys_hashes:+%5BHash%3B+32%5D,%0A%7D%0A%0A%23%5Bpanic_handler%5D%0Apub+fn+panic(_info:+%26panic::PanicInfo)+-%3E+!!+%7B%0A%09/*+We+always+run+panic%3Dabort+*/%0A%09unsafe+%7B+abort()%3B+%7D%0A%7D%0A%0A//+Stubs%0Aextern+%22Rust%22+%7B%0A%09fn+abort()+-%3E+!!%3B%0A++++fn+sha256(bytes:+%26%5Bu8%5D)+-%3E+%5Bu8%3B+32%5D%3B%0A++++fn+memcpy(dest:+*mut+u8,+src:+*const+u8,+n:+usize)%3B%0A%7D%0A'),l:'5',n:'0',o:'Rust+source+%231',t:'0')),k:67.41230591865605,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:nightly,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:rust,libs:!(),options:'--target%3Driscv32i-unknown-none-elf+-C+opt-level%3Ds+-C+panic%3Dabort+-C+codegen-units%3D1+-C+lto%3Dfat+-C+codegen-units%3D1+--cfg+!'feature%3D%22panic_immediate_abort%22!'',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1,tree:'1'),l:'5',n:'0',o:'rustc+nightly+(Rust,+Editor+%231,+Compiler+%231)',t:'0'),(h:output,i:(compilerName:'rustc+nightly',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+rustc+nightly+(Compiler+%231)',t:'0')),k:32.587694081343955,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

### Version it worked on

The last version I got it to run on was `nightly-2022-02-01`, but it might be working until as late as `2022-02-28` (I had some unrelated compile errors that made bisecting hard).

### Version with regression

The older nightly with regression is `2022-03-12`

`rustc --version --verbose`:
```
rustc 1.61.0-nightly (335ffbfa5 2022-03-11)
binary: rustc
commit-hash: 335ffbfa547df94ac236f5c56130cecf99c8d82b
commit-date: 2022-03-11
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
```