Conversation
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Prepare NonNull for pattern types
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (ea5f33e): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary -0.7%, secondary 8.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 481.396s -> 480.639s (-0.16%) |
This comment has been minimized.
This comment has been minimized.
library/core/src/ptr/non_null.rs
Outdated
| let pointer: *const T = crate::ptr::without_provenance(addr.get()); | ||
| // SAFETY: we know `addr` is non-zero. | ||
| unsafe { NonNull { pointer } } | ||
| unsafe { NonNull { pointer: transmute(pointer) } } |
There was a problem hiding this comment.
up to you: if this is going to transmute anyway, maybe just transmute directly to NonNull?
Going through the usize then the pointer then the aggregate doesn't seem particularly meaningful; maybe just go straight NonZero→NonNull if there needs to be a transmute here regardless?
There was a problem hiding this comment.
I also tried going from *const T to NonNull directly without going through the field constructor. It causes slightly worse MIR, because we don't really handle things like cast well in that case (NonZero transmute to raw pointer, cast, transmute back to NonZero).
| #[no_mangle] | ||
| pub fn load_box<'a>(x: Box<Box<i32>>) -> Box<i32> { | ||
| // CHECK: load ptr, ptr %{{.*}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !align ![[ALIGN_4_META]], !noundef !{{[0-9]+}} | ||
| // CHECK: load ptr, ptr %{{.*}}, align [[PTR_ALIGNMENT]], !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}} |
There was a problem hiding this comment.
Hmm, if this is showing up here with just the nonnull change it looks like whatever emits this !align needs an update to see through pattern types, maybe?
There was a problem hiding this comment.
This PR doesn't use pattern types yet 😅 so the issue is likely that we lose the information somewhere in the transmute. Lemme try your other suggestion, which maybe LLVM can preserve things if things are simpler
There was a problem hiding this comment.
Oh, doh, of course it doesn't use pattern types 🤦
Note that this is a -C no-prepopulate-passes test, though, so it's only testing things that we in cg_llvm actually emit for the loads. So this implies that it's loading as a pointer instead of as a Box, somehow, I guess?
(I was going to say "well if it's just llvm adding this maybe I'm not worried about it", but if it's us in cg_llvm adding it then presumably it's worth trying to keep it working.)
There was a problem hiding this comment.
Hmm, thinking more about what you said about the transmute, I wonder if this is something I regressed a long time ago with moving transmute to being primitive instead of always going through memory. Box<Box<i32>> and Box<i32> are both BackendAbi::Scalar, so maybe something is passed through a transmute now instead of being loaded from an alloca as the Box which would be where the !align on the load would be coming from...
I think that pushes me to just r=me for this stuff, as if it's an existing "oh this combination isn't great" that's not this PR's problem, and we can reoptimize it later as needed.
b11fecb to
349c689
Compare
|
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. |
| _24 = copy _25 as *mut u8 (PtrToPtr); | ||
| StorageDead(_25); | ||
| _23 = copy _24 as std::ptr::NonNull<u8> (Transmute); | ||
| - StorageDead(_24); | ||
| + nop; | ||
| _13 = copy _23 as *mut u8 (Transmute); |
There was a problem hiding this comment.
I think we need to teach gvn about skipping transmutes that go back and forth 😆
There was a problem hiding this comment.
ah... we explicitly skip them with transmute_may_have_niche_of_interest_to_backend. Maybe we could unconditionally fold them, but also emit an assume?
There was a problem hiding this comment.
Yeah, that's harder in GVN because GVN doesn't like updating things other than the value. (Also because of the fat-to-thin pointer cast. If fat pointers were just a struct things could be much easier here since part of the complication to folding is the transmute of the fat pointer.)
Musing: Maybe we always fold in GVN, but change the "remove unnecessary statements" code to emit an assume for an "unnecessary" transmute that creates a validity restriction? Dunno where the best place to do this would be.
(Of course, the other thing I would like is just a native "non-null with const-generic alignment" opaque pointer type. Whenever I see MIR needing to worry about *mut u8 vs *const u8 or about *mut u8 vs *mut () I get sad.)
|
The job Click to see the possible cause of the failure (guessed by this bot)For more information how to resolve CI failures of this job, visit this link. |
Pull out the changes that affect some tests, but do not require pattern types.
See #136006 (comment) for what triggered this PR
r? @scottmcm