Allow BackendRepr::Scalar for repr(Rust, packed) structs [MCP1007]#159033
Open
scottmcm wants to merge 2 commits into
Open
Allow BackendRepr::Scalar for repr(Rust, packed) structs [MCP1007]#159033scottmcm wants to merge 2 commits into
BackendRepr::Scalar for repr(Rust, packed) structs [MCP1007]#159033scottmcm wants to merge 2 commits into
Conversation
Collaborator
|
|
scottmcm
commented
Jul 9, 2026
Comment on lines
+24
to
+29
| pub unsafe fn write_packed_scalar(ptr: *mut PackedScalar, val: PackedScalar) { | ||
| // CHECK: start | ||
| // CHECK-NEXT: store i64 %val, ptr %ptr, align 2 | ||
| // CHECK-NEXT: ret void | ||
| *ptr = val; | ||
| } |
Member
Author
There was a problem hiding this comment.
Compare what we emit today: https://rust.godbolt.org/z/8Pv61EhbK
This one, for example, emits 2 allocas and 2 memcpys without this PR:
define void @write_packed_scalar(ptr noundef %ptr, i64 noundef %0) unnamed_addr {
start:
%1 = alloca [8 x i8], align 8
%val = alloca [8 x i8], align 2
call void @llvm.lifetime.start.p0(ptr %1)
store i64 %0, ptr %1, align 8
call void @llvm.memcpy.p0.p0.i64(ptr align 2 %val, ptr align 8 %1, i64 8, i1 false)
call void @llvm.lifetime.end.p0(ptr %1)
call void @llvm.memcpy.p0.p0.i64(ptr align 2 %ptr, ptr align 2 %val, i64 8, i1 false)
ret void
}(which LLVM of course cleans up even in -O1, but still nice to just not emit that in the first place.)
scottmcm
commented
Jul 9, 2026
This was referenced Jul 9, 2026
RalfJung
reviewed
Jul 10, 2026
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Jul 12, 2026
…uct, r=joshtriplett
Better comment the struct used by `{read,write}_unaligned`
To address rust-lang#159033 (comment)
r? @RalfJung
This comment has been minimized.
This comment has been minimized.
rust-timer
added a commit
that referenced
this pull request
Jul 12, 2026
Rollup merge of #159157 - scottmcm:clearer-ptr-unaligned-struct, r=joshtriplett Better comment the struct used by `{read,write}_unaligned` To address #159033 (comment) r? @RalfJung
44a579c to
2c6804e
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
2c6804e to
de892dd
Compare
RalfJung
reviewed
Jul 13, 2026
de892dd to
2c6804e
Compare
Co-authored-by: Ralf Jung <post@ralfj.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tracking issue: #158985
This only changes
Scalar(notScalarPairnorSimdVector) because I wanted to do this in small bites. It also preserves the requirement that there can't be padding, so won't apply foralign(MORE_THAN_SIZE)either. I also didn't touch unions.Note that after #158666 there are zero mentions of
default_alignin codegen, so this "just working" in codegen without any changes is IMHO expected. Codegen has long been expected to always use PlaceValue::align instead of anything from the layout when dealing with alignment.r? workingjubilee