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

Allow MIR debuginfo to point to a variable's address #111440

Merged
merged 8 commits into from
May 14, 2023

Conversation

cjgillot
Copy link
Contributor

MIR optimizations currently do not to operate on borrowed locals.

When enabling #106285, many borrows will be left as-is because they are used in debuginfo. This pass allows to replace this pattern directly in MIR debuginfo:

a => _1
_1 = &raw? mut? _2

becomes

a => &_2
// No statement to borrow _2.

This pass is implemented as a drive-by in ReferencePropagation MIR pass.

This transformation allows following following MIR opts to treat _2 as an unborrowed local, and optimize it as such, even in builds with debuginfo.

In codegen, when encountering a => &..&_2, we create a list of allocas:

store ptr %_2.dbg.spill, ptr %a.ref0.dbg.spill
store ptr %a.ref0.dbg.spill, ptr %a.ref1.dbg.spill
...
call void @llvm.dbg.declare(metadata ptr %a.ref{n}.dbg.spill, /* ... */)

Caveat: this transformation looses the exact type, we do not differentiate a as a immutable, mutable reference or a raw pointer. Everything is declared to *mut to codegen. I'm not convinced this is a blocker.

@rustbot
Copy link
Collaborator

rustbot commented May 10, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@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 May 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 10, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@jackh726
Copy link
Member

r? mir-opt

@rustbot rustbot assigned oli-obk and unassigned jackh726 May 11, 2023
@oli-obk
Copy link
Contributor

oli-obk commented May 12, 2023

r=me with the debuginfo test extended to have a case where references is 2 or more.

@bors
Copy link
Contributor

bors commented May 12, 2023

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

@cjgillot
Copy link
Contributor Author

@oli-obk to simplify triggering the case with 2 or more references, I added 1965237 too. Is the debuginfo test sufficient, or do you need me to check more than 2?

@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2023

That's perfect, thanks!

@bors r+

@bors
Copy link
Contributor

bors commented May 13, 2023

📌 Commit 8fb888d has been approved by oli-obk

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 May 13, 2023
@bors
Copy link
Contributor

bors commented May 14, 2023

⌛ Testing commit 8fb888d with merge bc88895...

@bors
Copy link
Contributor

bors commented May 14, 2023

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing bc88895 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 14, 2023
@bors bors merged commit bc88895 into rust-lang:master May 14, 2023
11 checks passed
@rustbot rustbot added this to the 1.71.0 milestone May 14, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bc88895): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was 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)
-2.6% [-2.6%, -2.6%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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)
4.7% [4.2%, 5.5%] 3
Regressions ❌
(secondary)
2.3% [2.1%, 2.5%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 4.7% [4.2%, 5.5%] 3

Cycles

Results

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)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) - - 0

Binary size

Results

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.2%] 59
Regressions ❌
(secondary)
0.1% [0.0%, 0.2%] 32
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.2%] 59

Bootstrap: 661.349s -> 660.613s (-0.11%)

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.

None yet

6 participants