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

Invalidate all dereferences when encountering non-local assignments #132527

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

DianQK
Copy link
Member

@DianQK DianQK commented Nov 2, 2024

Fixes #132353.

This PR removes the computation value by traversing SSA locals through for_each_assignment_mut.

Because the for_each_assignment_mut traversal skips statements which have side effects, such as dereference assignments, the computation may be unsound. Instead of for_each_assignment_mut, we compute values by traversing in reverse postorder.

Because we compute and use the symbolic representation of values on the fly, I invalidate all old values when encountering a dereference assignment. The current approach does not prevent the optimization of a clone to a copy.

In the future, we may add an alias model, or dominance information for dereference assignments, or SSA form to help GVN.

r? cjgillot

cc @jieyouxu #132356
cc @RalfJung #133474

@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 Nov 2, 2024
@DianQK DianQK changed the title [WIP] Invalidate all dereferences when encountering non-local assignments. [WIP] Invalidate all dereferences when encountering non-local assignments Nov 2, 2024
@DianQK
Copy link
Member Author

DianQK commented Nov 2, 2024

@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 Nov 2, 2024
@bors
Copy link
Contributor

bors commented Nov 2, 2024

⌛ Trying commit 64d0f48 with merge 0011660...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 2, 2024
[WIP] Invalidate all dereferences when encountering non-local assignments

Fixes rust-lang#132353.

r? ghost
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Nov 2, 2024

☀️ Try build successful - checks-actions
Build commit: 0011660 (0011660807de999202661fd942d6b7f77fdc9c8e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0011660): comparison URL.

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

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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.5% [0.3%, 0.7%] 3
Regressions ❌
(secondary)
0.5% [0.2%, 0.7%] 10
Improvements ✅
(primary)
-1.2% [-6.4%, -0.2%] 14
Improvements ✅
(secondary)
-0.5% [-0.6%, -0.5%] 10
All ❌✅ (primary) -0.9% [-6.4%, 0.7%] 17

Max RSS (memory usage)

Results (primary -0.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)
3.3% [2.1%, 5.8%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-6.9% [-10.5%, -3.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-10.5%, 5.8%] 6

Cycles

Results (primary -1.6%)

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.8% [0.8%, 0.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.1% [-5.8%, -0.8%] 5
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.6% [-5.8%, 0.8%] 6

Binary size

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

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.1% [0.0%, 0.4%] 33
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 14
Improvements ✅
(primary)
-0.3% [-2.4%, -0.0%] 23
Improvements ✅
(secondary)
-0.7% [-1.2%, -0.0%] 10
All ❌✅ (primary) -0.1% [-2.4%, 0.4%] 56

Bootstrap: 780.173s -> 782.091s (0.25%)
Artifact size: 335.37 MiB -> 335.25 MiB (-0.03%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Nov 2, 2024
@DianQK DianQK added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 16, 2024
@DianQK
Copy link
Member Author

DianQK commented Nov 16, 2024

I will update this after #132461.

@DianQK DianQK removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 3, 2024
@DianQK
Copy link
Member Author

DianQK commented Dec 4, 2024

@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 Dec 4, 2024
@bors
Copy link
Contributor

bors commented Dec 4, 2024

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout gvn-stmt-iter (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self gvn-stmt-iter --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir
CONFLICT (content): Merge conflict in tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-unwind.mir
Auto-merging tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir
CONFLICT (content): Merge conflict in tests/mir-opt/pre-codegen/vec_deref.vec_deref_to_slice.PreCodegen.after.panic-abort.mir
Automatic merge failed; fix conflicts and then commit the result.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Dec 4, 2024
@bors
Copy link
Contributor

bors commented Dec 4, 2024

☔ The latest upstream changes (presumably #133841) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@DianQK
Copy link
Member Author

DianQK commented Dec 4, 2024

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2024
[WIP] Invalidate all dereferences when encountering non-local assignments

Fixes rust-lang#132353.

r? ghost
@bors
Copy link
Contributor

bors commented Dec 21, 2024

⌛ Trying commit 199b7f9 with merge 0754bc9...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 21, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 21, 2024
@bors
Copy link
Contributor

bors commented Dec 22, 2024

☔ The latest upstream changes (presumably #134330) made this pull request unmergeable. Please resolve the merge conflicts.

@DianQK
Copy link
Member Author

DianQK commented Dec 22, 2024

The job x86_64-mingw-1 failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)

Should fix by #134608.

@DianQK
Copy link
Member Author

DianQK commented Dec 22, 2024

☔ The latest upstream changes (presumably #134330) made this pull request unmergeable. Please resolve the merge conflicts.

I rebased.

}
// Function calls maybe invalidate nested deref, and non-local assignments maybe invalidate deref.
// Currently, no distinction is made between these two cases.
self.invalidate_derefs();
Copy link
Contributor

Choose a reason for hiding this comment

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

I fear we are missing many cases of indirect writes. For example, inline asm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of addressing to which terminator may write something, I adopted a more conservative approach, which terminator must not write anything.

@DianQK
Copy link
Member Author

DianQK commented Dec 23, 2024

@bors r-

@DianQK
Copy link
Member Author

DianQK commented Jan 7, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 7, 2025
@bors
Copy link
Contributor

bors commented Jan 17, 2025

☔ The latest upstream changes (presumably #135592) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk removed their assignment Jan 23, 2025
@DianQK
Copy link
Member Author

DianQK commented Jan 24, 2025

I have rebased.

@oli-obk Since @cjgillot may be busy, would you like to review it again?
btw, I think you might have forgotten to update your GitHub profile status? :p

@bors
Copy link
Contributor

bors commented Jan 26, 2025

☔ The latest upstream changes (presumably #135753) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 28, 2025

would you like to review it again?

I think I'll leave it to the expert who keeps finding things I missed ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic in nightly 1.83.0 and 1.84.0 with opt-level >= 1 when unwrapping Some variant
7 participants