Uh oh!
There was an error while loading. Please reload this page.
Preserve metadata like !range and !nonnull in unaligned operations - #158202
Preserve metadata like !range and !nonnull in unaligned operations#158202scottmcm wants to merge 2 commits into
!range and !nonnull in unaligned operations#158202Conversation
rustbot
commented
Jun 21, 2026
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
cc @rust-lang/wg-const-eval |
rustbot
commented
Jun 21, 2026
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
0201cff to
2bb0b89Compare
This comment has been minimized.
This comment has been minimized.
2bb0b89 to
e1341acCompareYou know what, thinking about this today, I might be able to just do this with a MIR-opt instead. The problem I hit was basically _3 = Packed(_2);*_1 = move _3;and I can probably GVN that to (*_1).0 = _2;instead of needing the intrinsic to do it... @rustbot author EDIT: well, probably not GVN actually, but maybe SRoA? |
Today, unaligned loads lose their
!rangemetadata in codegen: https://rust.godbolt.org/z/rjdq51o7EThat's because it goes through
copy_nonoverlapping::<u8>, it seems, which is an untyped copy so that's what theloadends up being.I started fixing that in codegen, adding an intrinsic with fallback mir since it'd be easy to emit in cg_ssa by setting the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_ssa/mir/place/struct.PlaceValue.html#structfield.align to
Align::ONE.But then I realized that we have a way to do that in native Rust:
repr(packed).Unfortunately just doing it in pure rust in the library isn't enough because reading a
repr(packed)type again emits allvm.memcpy, leading to the same problem. (This is because all packed types end up withBackendRepr::Memoryhttps://rust.godbolt.org/z/37dee8dqr it looks like.)But that's ok, since it's still possible to do this in MIR that all the backends already need to handle 🎉
cc @RalfJung who I'm confident will have opinions about these new intrinsics