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

Add an InstSimplify for repetitive array expressions #135274

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Jan 9, 2025

I noticed in #135068 (comment) that GVN's implementation of this same transform was quite profitable on the deep-vector benchmark. But of course GVN doesn't run in unoptimized builds, so this is my attempt to write a version of this transform that benefits the deep-vector case and is fast enough to run in InstSimplify.

The benchmark suite indicates that this is effective.

@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 9, 2025
@saethlin
Copy link
Member Author

saethlin commented Jan 9, 2025

@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 9, 2025
@saethlin saethlin added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-waiting-on-perf Status: Waiting on a perf run to be completed. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2025
@saethlin
Copy link
Member Author

saethlin commented Jan 9, 2025

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 9, 2025
Add an InstSimplify for repetitive array expressions

r? ghost

Let's see if this even perfs well.
@bors
Copy link
Contributor

bors commented Jan 9, 2025

⌛ Trying commit d767dd8 with merge 9811408f4eb6418d113324d8e3609a0a84b54664...

@bors
Copy link
Contributor

bors commented Jan 9, 2025

☀️ Try build successful - checks-actions
Build commit: 9811408 (9811408f4eb6418d113324d8e3609a0a84b54664)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9811408): comparison URL.

Overall result: ✅ 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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-14.6% [-27.9%, -1.2%] 9
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.8%, secondary -11.7%)

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.8% [2.8%, 2.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-11.7% [-18.3%, -0.8%] 6
All ❌✅ (primary) 2.8% [2.8%, 2.8%] 1

Cycles

Results (secondary -28.4%)

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)
-28.4% [-33.2%, -10.9%] 5
All ❌✅ (primary) - - 0

Binary size

Results (secondary -25.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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-25.2% [-25.2%, -25.2%] 5
All ❌✅ (primary) - - 0

Bootstrap: 764.798s -> 763.387s (-0.18%)
Artifact size: 325.77 MiB -> 325.71 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 9, 2025
@rust-log-analyzer

This comment has been minimized.

@saethlin saethlin added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. labels Jan 9, 2025
@saethlin saethlin marked this pull request as ready for review January 9, 2025 22:29
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@saethlin
Copy link
Member Author

saethlin commented Jan 9, 2025

@saethlin
Copy link
Member Author

saethlin commented Jan 9, 2025

r? mir-opt

let Operand::Constant(field) = field else {
return false;
};
let field = field.const_.eval(self.tcx, self.typing_env, field.span);
Copy link
Member

Choose a reason for hiding this comment

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

Would be cool to see more tests exercising this eval call. Specifically, maybe something like [CONST, CONST, ...] for some global const, something with ZSTs, something gauging whether or not it works with things like nested slices/string lits (probably doesn't? const eval doesn't deduplicate allocations like that right?)

Copy link
Member Author

@saethlin saethlin Jan 10, 2025

Choose a reason for hiding this comment

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

The optimization doesn't work on ZSTs. Ultimately that doesn't matter because RemoveZsts will run before InstSimplify and completely eliminate the statement we would optimize.

But it makes me a bit worried that this doesn't work with ZSTs because we generate a local per array element for ZSTs, but we don't for a numeric literal, and this optimization relies on generating an Operand::Const, not a local per array element that we then Move from.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

ty for the tests

r=me

@saethlin
Copy link
Member Author

r? compiler-errors
@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 10, 2025

📌 Commit a285d20 has been approved by compiler-errors

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Jan 10, 2025

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

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

bors commented Jan 11, 2025

⌛ Testing commit a285d20 with merge 7e4077d...

@bors
Copy link
Contributor

bors commented Jan 11, 2025

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 7e4077d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 11, 2025
@bors bors merged commit 7e4077d into rust-lang:master Jan 11, 2025
7 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 11, 2025
@saethlin saethlin deleted the array-repeats branch January 11, 2025 12:11
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7e4077d): comparison URL.

Overall result: ✅ improvements - 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
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-14.7% [-27.9%, -1.3%] 9
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary -12.1%)

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)
-12.1% [-18.1%, -3.4%] 6
All ❌✅ (primary) - - 0

Cycles

Results (secondary -18.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)
- - 0
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-21.2% [-33.7%, -3.2%] 7
All ❌✅ (primary) - - 0

Binary size

Results (secondary -25.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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-25.2% [-25.2%, -25.1%] 5
All ❌✅ (primary) - - 0

Bootstrap: 763.776s -> 765.598s (0.24%)
Artifact size: 326.00 MiB -> 325.92 MiB (-0.02%)

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2025
Use Box::new instead of the box_new intrinsic in vec! expansion

r? ghost

This should perf differently since rust-lang#135274 landed.

Some UI tests are failing locally and seem to indicate a diagnostic regression that I'll fix if this perfs well.
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.

7 participants