Repository navigation
Add rustc_nounwind to various std functions - #166589
nnethercote wants to merge 1 commit into
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.
Add `rustc_nounwind` to various std functions
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The presence of this attribute changes `invoke` occurrences in LLVM IR
to `call`, which means LLVM can use the fast `FastISel` instruction
selector instead of the `SelectionDAG` selector in debug builds.
Justification for these annotations is primarily semantic -- these
functions should never unwind.
- Various `deref`/`deref_mut`/`as_ref`: borrow existing contents.
- `Option::is_{some,none}`, `Vec::{len,is_empty}`, `NonZero::get`:
observe existing state.
- `Option::take`, `{Option,Result}::branch`, `mem::forget`: transfer or
relinquish ownership without running `drop`.
- `{Option,Result}::from_output`, `Pin::new_unchecked`,
`{Path,OsStr}::display`, `Arguments::{new,from_str}`: simple wrappers.
- `{Vec,String}::new`: construct an empty container (no allocation).
- `{slice,Vec::IntoIter}::next`: advance an iterator; exhaustion via `None`.
- `Argument` constructors: just bundle up some arguments.
- `OsString::{index,index_mut}` with `RangeFull`: just address
manipulation.
- `fetch_add`: wrapping add, no failure mode.
- `maybe_is_nonoverlapping`: comparison op, already uses
`panic_nounwind` on mul overflow.
- `must_use`: literally the identity function (with special warning
behaviour).
If any of these functions were ever changed such that they could unwind,
these annotations mean they would instead abort. But such a change would
be a bug anyway. The nounwind property is also generally clear by
looking at the code inside each function.
|
Finished benchmarking commit (0b06dff): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never rustc-perf 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 1.3%, secondary 0.5%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.3%, secondary -1.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.2%, secondary -0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 461.669s -> 462.551s (0.19%) |
Thanks for the cc:> Hmm... that doesn't seem to be entirely the subset. In my view, adding the |
|
It does feel like this is something we should be able to have the compiler infer. But my initial impression of #165326 is that it won’t be an easy or quick review. Also, the current state of that PR is trying to do much more than should be necessary for this PR: most if not all functions annotated here should be leaf functions (after MIR inlining their callees), so a shallow analysis that side-steps complications like query cycles should be sufficient. So I don’t think we necessarily need to block the perf wins here on #165326 (if we’d otherwise be happy with the manual annotations). On the contrary, it might be useful to pick the low hanging fruit like this first and see if that changes the cost/benefit analysis for the bigger, more general hammer. |
I totally agree with that haha:> My guess is that if this PR gets merged first, then when #165326 is subsequently benchmarked via rust-perf, we might see some "free" performance gains, I suppose with these functions marked |
5a6b590 to
b573a78
Compare
|
Some changes occurred in library/core/src/fmt/rt.rs cc @m-ou-se |
|
I updated the mir-opt expected output, which should fix those test failures. I didn't know about #165326 until @petrochenkov mentioned it. The annotation-by-hand approach is definitely the quick and dirty win; I just annotated the functions that were showing up the most in a couple of benchmarks that I tried. Sounds like people aren't opposed to this PR, so I have moved it out of draft state and asked @cuviper for review, but if there's a more appropriate reviewer please let me know. |
The presence of this attribute changes
invokeoccurrences in LLVM IR tocall, which means LLVM can use the fastFastISelinstruction selector instead of theSelectionDAGselector in debug builds.Justification for these annotations is primarily semantic -- these functions should never unwind.
Various
deref/deref_mut/as_ref: borrow existing contents.Option::is_{some,none},Vec::{len,is_empty},NonZero::get: observe existing state.Option::take,{Option,Result}::branch,mem::forget: transfer or relinquish ownership without runningdrop.{Option,Result}::from_output,Pin::new_unchecked,{Path,OsStr}::display,Arguments::{new,from_str}: simple wrappers.{Vec,String}::new: construct an empty container (no allocation).{slice,Vec::IntoIter}::next: advance an iterator; exhaustion viaNone.Argumentconstructors: just bundle up some arguments.OsString::{index,index_mut}withRangeFull: just address manipulation.fetch_add: wrapping add, no failure mode.maybe_is_nonoverlapping: comparison op, already usespanic_nounwindon mul overflow.must_use: literally the identity function (with special warning behaviour).If any of these functions were ever changed such that they could unwind, these annotations mean they would instead abort. But such a change would be a bug anyway. The nounwind property is also generally clear by looking at the code inside each function.
r? @cuviper