Skip to content

Conversation

dianqk
Copy link
Member

@dianqk dianqk commented Oct 12, 2025

Fix a miscompiled case I found when re-reviewing #132527.

r? cjgillot
r? oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 Oct 12, 2025
@dianqk
Copy link
Member Author

dianqk commented Oct 12, 2025

I want to backport the first two commits.

@rustbot label beta-nominated

@rustbot rustbot added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 12, 2025
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this. I had a more brutal solution in mind, yours preserves more opts.
r=me with some nits

View changes since this review

Comment on lines 54 to 55
#[path = "loop.rs"]
pub mod loop_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#[path = "loop.rs"]
pub mod loop_;
pub mod loops;

To avoid having to use a path attribute.


let reverse_postorder = body.basic_blocks.reverse_postorder().to_vec();
for bb in reverse_postorder {
// N.B. With loops, reverse postorder cannot produce a valid topological order.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mind expanding the comment a bit?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but I was expecting something like:

// A statement or terminator from inside the loop, that is not processed yet, may have performed an indirect write.

@jackh726
Copy link
Member

Just for clarity re. backport: this has been broken since 1.88? What's the benefit of beta backporting?


let reverse_postorder = body.basic_blocks.reverse_postorder().to_vec();
for bb in reverse_postorder {
// N.B. With loops, reverse postorder cannot produce a valid topological order.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, but I was expecting something like:

// A statement or terminator from inside the loop, that is not processed yet, may have performed an indirect write.

// | bb3 | |
// | *x=c | -+
// +------+
if maybe_loop {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be enough to check maybe_loop_headers.contains(bb)?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think so, maybe I'm too conservative.

@dianqk dianqk changed the title GVN: Invalidate derefs when a loop exists GVN: Invalidate derefs at loop headers Oct 14, 2025
@cjgillot
Copy link
Contributor

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Oct 14, 2025

📌 Commit 2048b9c has been approved by cjgillot

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 Oct 14, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 14, 2025
GVN: Invalidate derefs at loop headers

Fix a miscompiled case I found when re-reviewing rust-lang#132527.

r? cjgillot
r? oli-obk
bors added a commit that referenced this pull request Oct 14, 2025
Rollup of 11 pull requests

Successful merges:

 - #146277 (Enable `u64` limbs in `core::num::bignum`)
 - #146976 (constify basic Clone impls)
 - #147249 (Do two passes of `handle_opaque_type_uses_next`)
 - #147266 (fix 2 search graph bugs)
 - #147468 (Implement fs api set_times and set_times_nofollow)
 - #147497 (`proc_macro` cleanups (3/N))
 - #147594 (std: implement `pal::os::exit` for VEXos)
 - #147596 (Adjust the Arm targets in CI to reflect latest changes)
 - #147607 (GVN: Invalidate derefs at loop headers)
 - #147620 (Avoid redundant UB check in RangeFrom slice indexing)
 - #147647 (Hide vendoring and copyright in GHA group)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 14, 2025
GVN: Invalidate derefs at loop headers

Fix a miscompiled case I found when re-reviewing rust-lang#132527.

r? cjgillot
r? oli-obk
bors added a commit that referenced this pull request Oct 14, 2025
Rollup of 12 pull requests

Successful merges:

 - #146277 (Enable `u64` limbs in `core::num::bignum`)
 - #146976 (constify basic Clone impls)
 - #147249 (Do two passes of `handle_opaque_type_uses_next`)
 - #147266 (fix 2 search graph bugs)
 - #147497 (`proc_macro` cleanups (3/N))
 - #147546 (Suppress unused_parens for labeled break)
 - #147548 (Fix ICE for never pattern as closure parameters)
 - #147594 (std: implement `pal::os::exit` for VEXos)
 - #147596 (Adjust the Arm targets in CI to reflect latest changes)
 - #147607 (GVN: Invalidate derefs at loop headers)
 - #147620 (Avoid redundant UB check in RangeFrom slice indexing)
 - #147647 (Hide vendoring and copyright in GHA group)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4fc3a05 into rust-lang:master Oct 14, 2025
10 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 14, 2025
rust-timer added a commit that referenced this pull request Oct 14, 2025
Rollup merge of #147607 - dianqk:gvn-deref-loop, r=cjgillot

GVN: Invalidate derefs at loop headers

Fix a miscompiled case I found when re-reviewing #132527.

r? cjgillot
r? oli-obk
@saethlin
Copy link
Member

@rust-timer build 173ae98

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (173ae98): comparison URL.

Overall result: ✅ improvements - no action needed

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.

@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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
-1.2% [-1.2%, -1.2%] 1
All ❌✅ (primary) -1.3% [-1.3%, -1.3%] 1

Max RSS (memory usage)

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

Cycles

Results (primary 2.7%, secondary -2.5%)

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

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

Binary size

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

Bootstrap: 475.635s -> 474.033s (-0.34%)
Artifact size: 388.48 MiB -> 388.48 MiB (0.00%)

@dianqk dianqk deleted the gvn-deref-loop branch October 15, 2025 00:13
@bors
Copy link
Collaborator

bors commented Oct 15, 2025

⌛ Testing commit 2048b9c with merge 5413f7d...

@dianqk
Copy link
Member Author

dianqk commented Oct 15, 2025

@bors r-

@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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 15, 2025
@dianqk dianqk removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 15, 2025
@matthiaskrgr
Copy link
Member

@bors retry r-

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 15, 2025
@apiraino
Copy link
Contributor

Beta backport accepted as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Backport labels handled by them.

@rustbot label +beta-accepted

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Oct 16, 2025
@cuviper cuviper mentioned this pull request Oct 16, 2025
@cuviper cuviper modified the milestones: 1.92.0, 1.91.0 Oct 16, 2025
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Oct 16, 2025
bors added a commit that referenced this pull request Oct 17, 2025
[beta] backports

- Change int-to-ptr transmute lowering back to inttoptr #147541
- rewrite outlives placeholder constraints to outlives static when handling opaque types #147566
- GVN: Invalidate derefs at loop headers #147607

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

Labels

beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

10 participants