Skip to content
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

Update our range assumes to the format that LLVM prefers #135674

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jan 18, 2025

I found out in llvm/llvm-project#123278 (comment) that the way I started emitting the assumes in #109993 was suboptimal, and as seen in that LLVM issue the way we're doing it -- with two assumes sometimes -- can at times lead to CVP/SCCP not realize what's happening because one of them turns into a ne instead of conveying a range.

So this updates how it's emitted from

assume( x >= LOW );
assume( x <= HIGH );

or

// (for ranges that wrap the range)
assume( (x <= LOW) | (x >= HIGH) );

to

assume( (x - LOW) <= (HIGH - LOW) );

so that we don't need multiple icmps nor multiple assumes for a single value, and both wrappping and non-wrapping ranges emit the same shape.

(And we don't bother emitting the subtraction if LOW is zero, since that's trivial for us to check too.)

@rustbot
Copy link
Collaborator

rustbot commented Jan 18, 2025

r? @estebank

rustbot has assigned @estebank.
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 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 Jan 18, 2025
@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@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 Jan 18, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 18, 2025
Update our range `assume`s to the format that LLVM prefers

I found out in llvm/llvm-project#123278 (comment) that the way I started emitting the `assume`s in rust-lang#109993 was suboptimal, and as seen in that LLVM issue the way we're doing it -- with two `assume`s sometimes -- can at times lead to CVP/SCCP not realize what's happening because one of them turns into a `ne` instead of conveying a range.

So this updates how it's emitted from
```
assume( x >= LOW );
assume( x <= HIGH );
```
to
```
assume( (x - LOW) <= (HIGH - LOW) );
```
so that we don't need multiple `icmp`s nor multiple `assume`s for a single value.
@bors
Copy link
Contributor

bors commented Jan 18, 2025

⌛ Trying commit 6fe8200 with merge 37b0240...

@bors
Copy link
Contributor

bors commented Jan 18, 2025

☀️ Try build successful - checks-actions
Build commit: 37b0240 (37b0240d0706c13aff3886502fd74a0ddc2db9b1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (37b0240): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.5% [0.4%, 0.6%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -2.2%, secondary -0.8%)

This 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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.2% [-3.2%, -1.2%] 2
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 1
All ❌✅ (primary) -2.2% [-3.2%, -1.2%] 2

Cycles

Results (primary 2.0%)

This 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.

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

Binary size

Results (secondary -0.0%)

This 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.

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

Bootstrap: 765.445s -> 765.133s (-0.04%)
Artifact size: 326.00 MiB -> 326.04 MiB (0.01%)

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

@estebank estebank left a comment

Choose a reason for hiding this comment

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

The code changes look fine to me. I'm ok with landing this, if the perf results make sense to you.

@scottmcm
Copy link
Member Author

Yeah, these results are fine. I wasn't expecting an improvement, since it's very situational -- the optimizations were almost always the same in llvm/llvm-project#123278, except for one case where it seemed like assume(x >= 1) getting turned into assume(x != 0) confused something slightly.

I'll take simpler (no longer 3-cases) code in rustc and more canonical codegen (for what LLVM likes) so long as perf doesn't say it make perf materially worse.

@bors r=estebank

@bors
Copy link
Contributor

bors commented Jan 19, 2025

📌 Commit 6fe8200 has been approved by estebank

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 Jan 19, 2025
@bors
Copy link
Contributor

bors commented Jan 22, 2025

⌛ Testing commit 6fe8200 with merge b2728d5...

@bors
Copy link
Contributor

bors commented Jan 22, 2025

☀️ Test successful - checks-actions
Approved by: estebank
Pushing b2728d5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 22, 2025
@bors bors merged commit b2728d5 into rust-lang:master Jan 22, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 22, 2025
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b2728d5): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

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

Max RSS (memory usage)

Results (primary -0.4%, secondary 2.2%)

This 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.

mean range count
Regressions ❌
(primary)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
-2.6% [-2.6%, -2.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-2.6%, 1.7%] 2

Cycles

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

Binary size

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

This 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.

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

Bootstrap: 764.55s -> 765.273s (0.09%)
Artifact size: 326.05 MiB -> 325.95 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

5 participants