Repository navigation
Add LLVM range attributes to slice length parameters - #148350
Conversation
|
rustbot has assigned @JonathanBrouwer. Use |
| pub fn len_plus_ten_b(s: &[u32]) -> usize { | ||
| // CHECK: start: | ||
| // CHECK-NOT: add | ||
| // CHECK: %[[R:.+]] = add nuw nsw i{{.+}} %s.1, 10 |
There was a problem hiding this comment.
This file is the simplest demonstration of LLVM taking advantage of it. See https://rust.godbolt.org/z/7jxqsaaTx showing that it didn't know nuw/nsw for these things previously.
|
@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 LLVM range attributes to slice length parameters
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (398e28a): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -1.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.1%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 475.716s -> 474.193s (-0.32%) |
|
The size numbers are really interesting here. 112KB off I think instruction-wide it's close enough to neutral to be tolerable. Especially since the bootstrap time is green. |
|
Note that the compiler toolchain size sometimes changes e.g. by tens of KiB even on no-op/README changes :( Probably due to BOLT/PGO. |
|
I've reviewed the code and it is correct, the tests also look good. I'm however struggling to interpret the performance results. From my experience the bootstrap time & toolchain size are so noisy that I don't even look at them. The benchmarks are a bit more red than I like (and expect from this change) tho, I don't really understand why. Especially (To other reviewers, feel free to r=me if you can explain the perf) |
This comment has been minimized.
This comment has been minimized.
|
Do we need to make a new build? |
Add LLVM range attributes to slice length parameters
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (2d5ecaf): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @bors rollup=never 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 7.6%, secondary -3.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary -2.8%, secondary 0.3%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (primary -0.2%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 476.797s -> 476.639s (-0.03%) |
|
Ok so it is reproducible, good to know :) Still very confusing perf tho. I think that both improvements in the primary benchmarks may actually be noise, looking at the history graph. I think the perf is probably good enough to merge regardless? I'm not sure though, re-assigning to someone else to make the final decision r? compiler r=me,you if you agree performance is acceptable, I already reviewed the code and that looks good |
There was a problem hiding this comment.
I think the perf results are okay, the primary benchmarks basically just see small improvements and its only really secondary benchmarks that have small regressions. More information is typically good and could be used more by LLVM in future, so I'd prefer to output this.
|
@bors r+ |
|
@bors r=JonathanBrouwer,davidtwco rollup=never |
|
💡 This pull request was already approved, no need to approve it again.
|
|
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 1f880d9 (parent) -> 20383c9 (this PR) Test differencesShow 4 test diffsStage 1
Stage 2
Additionally, 2 doctest diffs were found. These are ignored, as they are noisy. Job group index
Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard 20383c9f1d84eb9b9c6668a1668ef68a81eae274 --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
|
Finished benchmarking commit (20383c9): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary -0.1%, secondary -0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 474.478s -> 472.257s (-0.47%) |
…onathanBrouwer,davidtwco Add LLVM range attributes to slice length parameters It'll take a bunch more work to do this in layout -- because of cycles in `struct Foo<'a>(&'a Foo<'a>);` -- so until we figure out how to do that well, just look for slices specifically and add the proper range for the length.
…onathanBrouwer,davidtwco Add LLVM range attributes to slice length parameters It'll take a bunch more work to do this in layout -- because of cycles in `struct Foo<'a>(&'a Foo<'a>);` -- so until we figure out how to do that well, just look for slices specifically and add the proper range for the length.
rustc 1.93 and 1.94 segfault in LoopVectorizePass on scale_cap, the step cap of the FIRE loop under Solver::run_fill, at opt-level 2 and 3. cargo build --release fails with them, and so does the Meson build that the gpridge easyconfig of EasyBuild runs. Debug builds, rustc 1.92 and older, and rustc 1.95 and newer compile it. Both toolchains ship LLVM 21.1.8. LLVM 21 vectorizes a maxnum reduction without fast-math flags by leaving the vector loop when a lane is NaN, and the scalar loop then resumes from the start of the last vector iteration. The end value of an induction other than the canonical counter, here the index i that steps by 3 and is read after the loop, becomes the step times a select of that iteration and the vector trip count. LLVM 21 does not treat a select of scalars as a scalar, so it asks for the last vector lane of that end value, which was never computed, and dereferences a null pointer. LLVM 22 has the missing case (llvm/llvm-project@ce44e0b63ad2); no 21.x release got it. Rust 1.93 is the first release to vectorize the loop: the range attributes it puts on slice lengths (rust-lang/rust#148350) make the bounds-check exits of the loop countable. rustc 1.92 reports an early exit and leaves the loop scalar. scale_cap now splits trial and origin into atoms with as_chunks::<3>, copies each atom out as an array, and folds f64::max over the atom distances and then the distance of the tail. No index outlives a loop. LLVM 21 compiles it at every opt-level and target-cpu tried, on x86-64 and aarch64, and so do rustc 1.88.0, 1.89.0, stable and nightly. The copies keep the max vectorized. Over references to the atoms, the inlined loop keeps llvm.experimental.noalias.scope.decl calls. With them, the cost model of LLVM 22 (rustc 1.95.0, and opt 22.1.8) finds vectorizing unprofitable, and that cap ran 1.5 to 1.9 times slower than the indexed loop there. By value, LLVM 21, 22 and 23 vectorize the max, and LLVM 20 vectorizes neither form. In a microbenchmark of a 4096-atom per-atom cap, the old and new code take 13.6 and 13.7 us with rustc 1.88.0, 13.8 and 9.1 us with 1.92.0, 9.0 and 8.9 us with 1.95.0, and 8.8 us each with 1.100.0. With 1.93 and 1.94 the new code takes 8.8 us. The bits are the same. Each atom computes dx * dx + dy * dy + dz * dz as before. The tail and whole-vector sums now start from -0.0 instead of 0.0, which no square changes. f64::max skips a NaN distance as the old loop did, and since no distance is -0.0 the vector lanes reach the same maximum in any order. A zero size can now be -0.0, and scale_cap rescales by neither zero. The rescale is unchanged, and an origin shorter than the trial still panics. New tests: a copy of the indexed loops writes the same bits as scale_cap for zero, -0.0 and trial == origin displacements, caps of 0, -0, -1, 1e-300, 0.05, 0.2, 1, 1e300, inf and NaN, and each of ten extreme and non-finite values at every position of trial and of origin. They cover lengths 0 to 13, 26 and 112 at six displacement scales, the last two long enough for the vectorized max to run several vector iterations, and 2000 random cases of up to 400 coordinates, per atom and over the whole vector. The copy reads its loop bound through black_box, or LLVM 21 would crash on the test build in release. Both panic on a short origin.
It'll take a bunch more work to do this in layout -- because of cycles in
struct Foo<'a>(&'a Foo<'a>);-- so until we figure out how to do that well, just look for slices specifically and add the proper range for the length.