-
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
Add assume
s to slice length calls
#122926
Conversation
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
91a7e3f
to
772322d
Compare
tests/codegen/slice-length-limits.rs
Outdated
// CHECK: %[[J:.+]] = phi [[USIZE]] | ||
// CHECK: %[[I:.+]] = phi [[USIZE]] | ||
// CHECK-NOT: phi | ||
// CHECK: add nuw nsw [[USIZE]] %[[I]], %[[J]] |
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.
Demo that this is neither nuw
nor nsw
today: https://rust.godbolt.org/z/ne1bMPqv9
%_16.us = add i64 %iter2.sroa.0.09.us, %iter.sroa.0.011.us, !dbg !56
tail call void @do_something(i64 noundef %_16.us), !dbg !58
Since `.len()` on slices is safe, let's see how this impacts things vs what we could do with 121965 and LLVM 19
772322d
to
eed1ccd
Compare
if let Some(elem_bytes) = std::num::NonZeroU64::new(elem_ty.size.bytes()) { | ||
let isize_max = (1_u64 << (bx.sess().target.pointer_width - 1)) - 1; | ||
let len_max = isize_max / elem_bytes; | ||
let limit = bx.icmp(IntPredicate::IntULE, length, bx.const_usize(len_max)); |
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.
I first tried doing this with assume(sge(len * elem_bytes, 0))
, but got worse results -- I think LLVM is confused by the SGE limit compared with other positive things, even though it actually simplifies ule(x, isize::MAX)
into sgt(x, -1)
.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Add `assume`s to slice length calls Since `.len()` on slices is safe, let's see how this impacts things vs what we could do with rust-lang#121965 and LLVM 19
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (b6cd5cf): 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: 669.588s -> 679.345s (1.46%) |
Wow it looks like that knocked a fair chunk of code out of librustc_driver.so |
See also #116542, which will add range metadata and niches to the slice length. If I can get it to work. |
I think I'll close it in this form, though -- the perf costs are pretty high. Hopefully #121965 lets this just be parameter metadata to get more benefits at lower cost. |
Since
.len()
on slices is safe, let's see how this impacts things vs what we could do with #121965 and LLVM 19