Skip to content

Conversation

@scottmcm
Copy link
Member

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.

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 31, 2025
pub fn len_plus_ten_b(s: &[u32]) -> usize {
// CHECK: start:
// CHECK-NOT: add
// CHECK: %[[R:.+]] = add nuw nsw i{{.+}} %s.1, 10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 31, 2025
Add LLVM range attributes to slice length parameters
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 31, 2025
@rust-bors
Copy link

rust-bors bot commented Nov 1, 2025

☀️ Try build successful (CI)
Build commit: 398e28a (398e28a631e9d9248dbf3cef0409d1b7a684b917, parent: 82ae0ee6487e93bd6c05167ccb2ef3485fdbc890)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (398e28a): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking 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 @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
1.0% [0.1%, 2.0%] 20
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
-0.4% [-0.7%, -0.1%] 15
All ❌✅ (primary) -0.1% [-0.4%, 0.2%] 2

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.1% [-4.1%, -4.1%] 1
All ❌✅ (primary) - - 0

Cycles

Results (secondary 0.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.1%, 3.8%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.9%, -2.1%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 14
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 37
All ❌✅ (primary) -0.1% [-0.2%, -0.0%] 14

Bootstrap: 475.716s -> 474.193s (-0.32%)
Artifact size: 390.89 MiB -> 390.71 MiB (-0.04%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 1, 2025
@scottmcm
Copy link
Member Author

scottmcm commented Nov 1, 2025

The size numbers are really interesting here. 112KB off librustc_driver.so, which has to be coming from a whole bunch of stuff optimizing out from knowing more about the lengths, since there's no other changes here.

I think instruction-wide it's close enough to neutral to be tolerable. Especially since the bootstrap time is green.

@Kobzol
Copy link
Member

Kobzol commented Nov 1, 2025

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.

@JonathanBrouwer
Copy link
Contributor

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 check builds should not be affected by this change, since this code does not even run for them. Out of interest, lets rerun perf and see how reproducible the results are: @rust-timer queue

(To other reviewers, feel free to r=me if you can explain the perf)

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 1, 2025
@rust-lang rust-lang deleted a comment from rust-bors bot Nov 1, 2025
@JonathanBrouwer
Copy link
Contributor

Do we need to make a new build?
@bors try

rust-bors bot added a commit that referenced this pull request Nov 1, 2025
Add LLVM range attributes to slice length parameters
@rust-bors

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Nov 1, 2025

☀️ Try build successful (CI)
Build commit: 2d5ecaf (2d5ecaf90d3d6ce5f705cf9a7cd2b5821e180a9d, parent: d85276b256a8ab18e03b6394b4f7a7b246176db7)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2d5ecaf): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking 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 @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
1.0% [0.1%, 1.9%] 20
Improvements ✅
(primary)
-1.2% [-3.0%, -0.3%] 3
Improvements ✅
(secondary)
-0.3% [-0.6%, -0.2%] 17
All ❌✅ (primary) -0.9% [-3.0%, 0.2%] 4

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.

mean range count
Regressions ❌
(primary)
7.6% [7.6%, 7.6%] 1
Regressions ❌
(secondary)
3.1% [3.1%, 3.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-5.7%, -0.9%] 12
All ❌✅ (primary) 7.6% [7.6%, 7.6%] 1

Cycles

Results (primary -2.8%, secondary 0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.1% [0.8%, 8.6%] 6
Improvements ✅
(primary)
-2.8% [-2.8%, -2.8%] 1
Improvements ✅
(secondary)
-4.2% [-7.0%, -1.5%] 5
All ❌✅ (primary) -2.8% [-2.8%, -2.8%] 1

Binary size

Results (primary -0.2%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.2% [-1.1%, -0.0%] 16
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 37
All ❌✅ (primary) -0.2% [-1.1%, -0.0%] 16

Bootstrap: 476.797s -> 476.639s (-0.03%)
Artifact size: 390.82 MiB -> 388.62 MiB (-0.56%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Nov 1, 2025
@JonathanBrouwer
Copy link
Contributor

JonathanBrouwer commented Nov 1, 2025

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

@rustbot rustbot assigned davidtwco and unassigned JonathanBrouwer Nov 1, 2025
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since this review

@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

📌 Commit 0ba7bcf has been approved by davidtwco

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2025
@JonathanBrouwer
Copy link
Contributor

@bors r=JonathanBrouwer,davidtwco rollup=never

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

📌 Commit 0ba7bcf has been approved by JonathanBrouwer,davidtwco

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

⌛ Testing commit 0ba7bcf with merge 20383c9...

@bors
Copy link
Collaborator

bors commented Nov 3, 2025

☀️ Test successful - checks-actions
Approved by: JonathanBrouwer,davidtwco
Pushing 20383c9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 3, 2025
@bors bors merged commit 20383c9 into rust-lang:master Nov 3, 2025
13 checks passed
@rustbot rustbot added this to the 1.93.0 milestone Nov 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

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 differences

Show 4 test diffs

Stage 1

  • [codegen] tests/codegen-llvm/slice-len-math.rs: [missing] -> pass (J0)

Stage 2

  • [codegen] tests/codegen-llvm/slice-len-math.rs: [missing] -> pass (J1)

Additionally, 2 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 20383c9f1d84eb9b9c6668a1668ef68a81eae274 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-aarch64-apple: 8534.6s -> 6996.5s (-18.0%)
  2. dist-apple-various: 4254.6s -> 3609.7s (-15.2%)
  3. x86_64-gnu-llvm-20-3: 6505.1s -> 5581.8s (-14.2%)
  4. pr-check-1: 1710.1s -> 1482.8s (-13.3%)
  5. aarch64-apple: 10260.3s -> 8956.0s (-12.7%)
  6. dist-loongarch64-musl: 5787.4s -> 5141.4s (-11.2%)
  7. armhf-gnu: 5139.6s -> 4589.6s (-10.7%)
  8. dist-x86_64-windows-gnullvm: 5314.8s -> 4780.0s (-10.1%)
  9. x86_64-gnu-llvm-21-3: 6246.9s -> 5679.4s (-9.1%)
  10. dist-powerpc64-linux: 5682.5s -> 5168.6s (-9.0%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (20383c9): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
0.7% [0.1%, 2.0%] 29
Improvements ✅
(primary)
-0.3% [-0.5%, -0.1%] 6
Improvements ✅
(secondary)
-0.3% [-0.7%, -0.1%] 27
All ❌✅ (primary) -0.3% [-0.5%, 0.2%] 7

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 14
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 37
All ❌✅ (primary) -0.1% [-0.2%, -0.1%] 14

Bootstrap: 474.478s -> 472.257s (-0.47%)
Artifact size: 390.89 MiB -> 390.71 MiB (-0.05%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants