-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UB Check blocks MIR inlining of Vec::deref
#123174
Comments
#121662 seems highly relevant, in that it introduced the monomorphization time branch IIUC |
#122975 may help, can you try again once that lands? |
That does look likely to be relevant, at least to the open-coded version; that the version using On the other hand, it somewhat feels like |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
I am not sure that PR fixes this. The replacement of the NullOp would occur after inlining, so we need the function to be a good inlining candidate in the first place in order to have its UbCheck removed. Resolving that was why I wrote #121767, to remove the huge penalty from the call. We could also special-case the check calls, they already have a special inliner attribute so what's a bit more magic 🙃 |
I tried this out with my reworked costs in #123179, but it still doesn't inline by default -- it needs the threshold to be raised to Seems like it's right on the edge. On nightly (2024-03-27) it took |
It was so close to the threshold that a touch of simplification in libcore got it inlining again for you. PR up: #123190 |
...instead of that previous one, changed to a new more holistic PR that also fixes this #123840 |
…gillot Add an intrinsic for `ptr::from_raw_parts(_mut)` Fixes rust-lang#123174 cc `@CAD97` `@saethlin` r? `@cjgillot` As suggested in rust-lang#123190 (comment), this adds a new `AggregateKind::RawPtr` for creating a pointer from its data pointer and its metadata. That means that `slice::from_raw_parts` and friends no longer need to hard-code pointer layout into `libcore`, and because it no longer does union hacks the MIR is shorter and more amenable to optimizations.
…cjgillot Add an intrinsic for `ptr::from_raw_parts(_mut)` Fixes rust-lang#123174 cc `@CAD97` `@saethlin` r? `@cjgillot` As suggested in rust-lang#123190 (comment), this adds a new `AggregateKind::RawPtr` for creating a pointer from its data pointer and its metadata. That means that `slice::from_raw_parts` and friends no longer need to hard-code pointer layout into `libcore`, and because it no longer does union hacks the MIR is shorter and more amenable to optimizations.
Rollup merge of rust-lang#123840 - scottmcm:aggregate-kind-rawptr, r=cjgillot Add an intrinsic for `ptr::from_raw_parts(_mut)` Fixes rust-lang#123174 cc `@CAD97` `@saethlin` r? `@cjgillot` As suggested in rust-lang#123190 (comment), this adds a new `AggregateKind::RawPtr` for creating a pointer from its data pointer and its metadata. That means that `slice::from_raw_parts` and friends no longer need to hard-code pointer layout into `libcore`, and because it no longer does union hacks the MIR is shorter and more amenable to optimizations.
Code
I tried this code: [playground]
I expected to see this happen: in release mode with default MIR optimization, both
closed
andopen
would generate equivalent optimized MIR — an inlined conversion from&Vec<u8>
to&[u8]
(deconstruct theVec
into ptr and len then build the&[_]
).Instead, this happened: On 1.77.0, the inlining happens as expected. On 1.78.0-beta.3 (2024-03-27 4147533),
<Vec<u8> as Deref>::deref
(vec_deref
foropen
) is called outline. Impactfully, the call is additionally not known to never unwind (-> [return: …, unwind continue]
in MIR), which likely impedes optimization around the call.vec_deref
MIR on stablevec_deref
MIR on betaOn stable,
vec_deref
's optimized MIR is a single straightline basic block. On beta, it contains aswitchInt
onUbCheck(LanguageUb)
guarding a conditional call tostd::slice::from_raw_parts::precondition_check
, resulting in four basic blocks including an MIR call operation. AIUI both of these metrics (block/call count) directly contribute to the MIR inlining heuristics.stable
slice::from_raw_parts
beta
slice::from_raw_parts
Version it worked on
It most recently worked on: Rust Stable 1.77.0
Version with regression
It isn't working on: Rust Beta 1.78.0-beta.3 (2024-03-27 4147533)
Meta
Found on irlo while looking at inlining behavior of
ToString
.@rustbot modify labels: +regression-from-stable-to-beta
(didn't do
-regression-untriaged
since I didn't try to narrow it any further than playground stable/beta, but don't know the convention here)cc @saethlin (IIRC you've been working on
assert_unsafe_precondition!
s and otherprecondition_check
s)The text was updated successfully, but these errors were encountered: