-
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
Remove some assume
s from slice iterators that don't do anything
#111282
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Just in case, since slice iterators really matter, |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit ec3a9bc with merge dc509d686d4afcd39ba3abd7c29cd106c2f9477b... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (dc509d686d4afcd39ba3abd7c29cd106c2f9477b): comparison URL. Overall result: no relevant changes - no 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. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. 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.
CyclesThis benchmark run did not return any relevant results for this metric. 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: 656.275s -> 653.825s (-0.37%) |
// CHECK: %[[START:.+]] = load ptr, ptr %it, | ||
// CHECK-SAME: !nonnull | ||
// CHECK-SAME: !noundef | ||
// CHECK: icmp eq ptr %[[START]], %[[END]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter which order the ptr comparison goes in? Sometimes LLVM likes to change that up a little.
Otherwise looks pretty good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, for eq
the order shouldn't matter. I wonder if I can put the [[vars]]
in a regex to allow either order...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I definitely can't use a regex to allow either, since the [[
syntax in regexes is character classes. Not sure how best to do this...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, yeah, I asked some LLVM devs and they basically were like "oh I dunno, I don't think we support that" so I think this is something we can't harden our tests against. Which isn't awful, I've seen operand swaps happen once or twice but that doesn't mean they're incredibly common.
@bors r+ rollup |
…r=workingjubilee Remove some `assume`s from slice iterators that don't do anything Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null. Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>. (I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer. The codegen test added in this PR fails if the other `assume` is removed.)
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#97320 (Stabilize const_ptr_read) - rust-lang#110770 (Limit lifetime of format_args!() with inlined args.) - rust-lang#111021 (Move some tests) - rust-lang#111215 (Various changes to name resolution of anon consts) - rust-lang#111242 (support set `rpath` option for each target independently) - rust-lang#111282 (Remove some `assume`s from slice iterators that don't do anything) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…r=the8472 Simplify the implementation of iterators over slices of ZSTs Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`. That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like rust-lang#42789, for example. This PR instead changes it to just `end = ptr::invalid(len)` instead. That's easier to think about (IMHO, at least) as well as easier to represent. `next` is still to big to get inlined into the mir-opt/pre-codegen/ tests, but if I bump the inline threshold to force it to show the whole thing, this implementation is also less MIR: ``` > git diff --numstat 241 370 tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.mir 255 329 tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.mir 184 216 tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.mir 182 254 tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.mir ``` (That's ≈70 lines less for `Iter::next`, for example.) r? `@ghost` ~~Built atop rust-lang#111282, so draft until that lands.~~
Because the start pointer is iterators is already a
NonNull
, we emit the appropriate!nonnull
metadata when loading the pointer to tell LLVM that it's non-null.Probably the best way to see that it's the metadata that's important (and not the
assume
) is to observe that LLVM actually removes theassume
from the optimized IR: https://rust.godbolt.org/z/KhE6G963n.(I also checked that, yes, the if-not-ZST
assume
onend
is still doing something: it's how there's a!nonnull
metadata on its load, even though it's an ordinary raw pointer. The codegen test added in this PR fails if the otherassume
is removed.)