Eliminate UbChecks for non-standard libraries#122975
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
02a2ef7 to
1f87613
Compare
This comment has been minimized.
This comment has been minimized.
RalfJung
left a comment
There was a problem hiding this comment.
Thanks!
There's also a comment at the enum NullOp that needs updating.
library/core/src/intrinsics.rs
Outdated
| @@ -2662,11 +2662,13 @@ pub const unsafe fn typed_swap<T>(x: *mut T, y: *mut T) { | |||
| } | |||
|
|
|||
| /// Returns whether we should perform some UB-checking at runtime. This evaluate to the value of | |||
There was a problem hiding this comment.
| /// Returns whether we should perform some UB-checking at runtime. This evaluate to the value of | |
| /// Returns whether we should perform some UB-checking at runtime. This eventually evaluates to | |
| /// `cfg!(debug_assertions)`, but behaves different from `cfg!` when mixing crates built with different | |
| /// flags: if the crate has debug assertions enabled or carries the `#[rustc_preserve_ub_checks]` | |
| /// attribute, evaluation is delayed until monomorphization (or until the call gets inlined into | |
| /// a crate that does not delay evaluation further); otherwise it can happen any time. |
library/core/src/intrinsics.rs
Outdated
| /// compiled with and without debug_assertions. The common case here is a user program built with | ||
| /// debug_assertions linked against the distributed sysroot which is built without debug_assertions. | ||
| /// debug_assertions linked against the distributed sysroot which is built without debug_assertions | ||
| /// but with `rustc_preserve_ub_checks`. |
There was a problem hiding this comment.
| /// but with `rustc_preserve_ub_checks`. | |
| /// but with `#[rustc_preserve_ub_checks]`. |
|
|
||
| fn simplify_ub_check(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { | ||
| if let Rvalue::NullaryOp(NullOp::UbChecks, _) = *rvalue { | ||
| let const_ = Const::from_bool(self.tcx, false); |
There was a problem hiding this comment.
| let const_ = Const::from_bool(self.tcx, false); | |
| let const_ = Const::from_bool(self.tcx, tcx.sess.opts.debug_assertions); |
library/core/src/intrinsics.rs
Outdated
| /// `cfg!(debug_assertions)` during monomorphization when using `rustc_preserve_ub_checks` or | ||
| /// `-Cdebug_assertions=yes`, otherwise it can evaluate at any time. |
There was a problem hiding this comment.
| /// `cfg!(debug_assertions)` during monomorphization when using `rustc_preserve_ub_checks` or | |
| /// `-Cdebug_assertions=yes`, otherwise it can evaluate at any time. |
library/core/src/intrinsics.rs
Outdated
| /// This intrinsic is evaluated after monomorphization, which is relevant when mixing crates | ||
| /// compiled with and without debug_assertions. The common case here is a user program built with |
There was a problem hiding this comment.
| /// This intrinsic is evaluated after monomorphization, which is relevant when mixing crates | |
| /// compiled with and without debug_assertions. The common case here is a user program built with | |
| /// The common case here is a user program built with |
1f87613 to
39f2b11
Compare
|
This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras |
|
Thanks for the detailed comments. I've fixed the failed test case. I should also add |
I'm not sure how to keep the comment synchronized; I copied a section and added a citation. |
Maybe it should just reference the intrinsic and not repeat anything. |
tests/mir-opt/inline/unwrap_unchecked.unwrap_unchecked.PreCodegen.after.panic-abort.mir
Show resolved
Hide resolved
39f2b11 to
1f349ad
Compare
| /// Returns whether we want to check for UB. | ||
| /// This returns the value of `cfg!(debug_assertions)` at monomorphization time. | ||
| /// Returns whether we should perform some UB-checking at runtime. | ||
| /// Refer to the comments in the `ub_checks` function. |
There was a problem hiding this comment.
| /// Refer to the comments in the `ub_checks` function. | |
| /// See the `ub_checks` intrinsic docs for details. |
1f349ad to
8823c37
Compare
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Eliminate `UbCheck` for non-standard libraries The purpose of this PR is to allow other passes to treat `UbChecks` as constants in MIR for optimization after rust-lang#122629. r? RalfJung
|
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
UbCheck for non-standard librariesUbChecks for non-standard libraries
|
Finished benchmarking commit (98cd703): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 670.407s -> 670.602s (0.03%) |
8823c37 to
7d7e9d4
Compare
|
💔 Test failed - checks-actions |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
During LLVM build, likely unrelated/spurious |
|
@bors retry #122671 (comment) |
Will you do this on #122610 or a new PR? I believe it's also acceptable to run such passes repeatedly. |
I think the |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (760e567): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 669.604s -> 667.865s (-0.26%) |
He wasn't talking about |
|
The pass ordering tweak experiment is: #123256 |
Run InstSimplify before UnreachablePropagation This is the pass ordering change I was musing about: rust-lang#122975 (comment) r? `@ghost`
Run InstSimplify before UnreachablePropagation This is the pass ordering change I was musing about: rust-lang#122975 (comment) r? `@ghost`
I think I understand now. The |
|
I think the more interesting variant would be to say that
Note that I have not checked whether this would even help for Vec::deref. It was just brought up in the discussion. This definitely needs a bit more design and exploration before someone attempts an implementation. |
Great. This seems helpful for the internals of the standard library. |
The purpose of this PR is to allow other passes to treat
UbChecksas constants in MIR for optimization after #122629.r? RalfJung