Skip to content

Don't try to remove assignments in SimplifyComparisonIntegral#158214

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
hanna-kruppe:issue-158206
Jun 22, 2026
Merged

Don't try to remove assignments in SimplifyComparisonIntegral#158214
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
hanna-kruppe:issue-158206

Conversation

@hanna-kruppe

@hanna-kruppe hanna-kruppe commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

The pass tried to opportunistically clean up an unnecessary assign statement if there's no other use of the comparison folded into a switchInt. The reasoning was that switchInt(move _N) prevents uses of _N in other blocks. The immediate problem is that the pass didn't check for other uses of the comparison result in the same block. This PR drops the cleanup logic entirely to fix #158206.

One could try to salvage the cleanup by doing another scan through the basic block and looking for other uses of the temporary. However, the other half of the reasoning (move prevents later uses) is also dubious. As the documentation of Operand::Move says:

This may additionally overwrite the place with uninit bytes, depending on how we decide in UCG#188. You should not emit MIR that may attempt a subsequent second load of this place without first re-initializing it.

This does not justify assuming "moves makes place uninitialized" semantics for the purpose of optimizations. At least for now, it doesn't seem possible to do this cleanup soundly without a whole-function analysis that looks at all uses, i.e., a general dead code elimination pass.

@rustbot

rustbot commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

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 Jun 21, 2026
@rustbot

rustbot commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

r? @dingxiangfei2009

rustbot has assigned @dingxiangfei2009.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 19 candidates

@cjgillot

Copy link
Copy Markdown
Contributor

Dead store elimination runs a second time after this pass, so leaving assignments around is not an issue.

@bors r+

@rust-bors

rust-bors Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a642d9b has been approved by cjgillot

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Jun 21, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 21, 2026
Don't try to remove assignments in SimplifyComparisonIntegral

The pass tried to opportunistically clean up an unnecessary assign statement if there's no other use of the comparison folded into a `switchInt`. The reasoning was that `switchInt(move _N)` prevents uses of `_N` in other blocks. The immediate problem is that the pass didn't check for other uses of the comparison result *in the same block*. This PR drops the cleanup logic entirely to fix rust-lang#158206.

One could try to salvage the cleanup by doing another scan through the basic block and looking for other uses of the temporary. However, the other half of the reasoning (`move` prevents later uses) is also dubious. As the documentation of `Operand::Move` says:

> This may additionally overwrite the place with uninit bytes, depending on how we decide in [UCG#188](rust-lang/unsafe-code-guidelines#188). You should not emit MIR that may attempt a subsequent second load of this place without first re-initializing it.

This does not justify assuming "moves makes place uninitialized" semantics for the purpose of optimizations. At least for now, it doesn't seem possible to do this cleanup soundly without a whole-function analysis that looks at all uses, i.e., a general dead code elimination pass.
@ChrisDenton ChrisDenton added beta-nominated Nominated for backporting to the compiler in the beta channel. stable-nominated Nominated for backporting to the compiler in the stable channel. labels Jun 21, 2026
@ChrisDenton

Copy link
Copy Markdown
Member

I've nominated this for beta and stable backport since I think #158206 has high severity.

rust-bors Bot pushed a commit that referenced this pull request Jun 21, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #156356 (bootstrap: add bootstrap step to run intrinsic-test in CI)
 - #157711 (Move proc-macro dlopen from proc-macro-srv to rustc_metadata)
 - #157836 (rebuild LLVM when `bootstrap.toml` config changes)
 - #158214 (Don't try to remove assignments in SimplifyComparisonIntegral)
 - #158226 (miri subtree update)
 - #158108 (Update actions/download-artifact action to v8.0.1)
 - #158150 (Update backtrace submodule to pick up AIX related fixes.)
 - #158178 (Use the target checking infrastructure for the diagnostic attributes)
 - #158195 (Add me to some rotation groups)
@rust-bors rust-bors Bot merged commit 5030e61 into rust-lang:main Jun 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 22, 2026
@hanna-kruppe hanna-kruppe deleted the issue-158206 branch June 22, 2026 06:59
@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

beta backport approved 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 are handled by them.

@rustbot rustbot added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jun 22, 2026
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jun 22, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#156356 (bootstrap: add bootstrap step to run intrinsic-test in CI)
 - rust-lang/rust#157711 (Move proc-macro dlopen from proc-macro-srv to rustc_metadata)
 - rust-lang/rust#157836 (rebuild LLVM when `bootstrap.toml` config changes)
 - rust-lang/rust#158214 (Don't try to remove assignments in SimplifyComparisonIntegral)
 - rust-lang/rust#158226 (miri subtree update)
 - rust-lang/rust#158108 (Update actions/download-artifact action to v8.0.1)
 - rust-lang/rust#158150 (Update backtrace submodule to pick up AIX related fixes.)
 - rust-lang/rust#158178 (Use the target checking infrastructure for the diagnostic attributes)
 - rust-lang/rust#158195 (Add me to some rotation groups)
pull Bot pushed a commit to p-avital/rust-analyzer that referenced this pull request Jun 22, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#156356 (bootstrap: add bootstrap step to run intrinsic-test in CI)
 - rust-lang/rust#157711 (Move proc-macro dlopen from proc-macro-srv to rustc_metadata)
 - rust-lang/rust#157836 (rebuild LLVM when `bootstrap.toml` config changes)
 - rust-lang/rust#158214 (Don't try to remove assignments in SimplifyComparisonIntegral)
 - rust-lang/rust#158226 (miri subtree update)
 - rust-lang/rust#158108 (Update actions/download-artifact action to v8.0.1)
 - rust-lang/rust#158150 (Update backtrace submodule to pick up AIX related fixes.)
 - rust-lang/rust#158178 (Use the target checking infrastructure for the diagnostic attributes)
 - rust-lang/rust#158195 (Add me to some rotation groups)
@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

stable backport approved 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 are handled by them.

@rustbot rustbot added the stable-accepted Accepted for backporting to the compiler in the stable channel. label Jun 22, 2026
@panstromek

panstromek commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

for #158228

@rust-timer build 6fd92a3

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (6fd92a3): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

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

Max RSS (memory usage)

Results (primary 3.7%)

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

mean range count
Regressions ❌
(primary)
3.7% [2.4%, 4.3%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.7% [2.4%, 4.3%] 3

Cycles

This perf run didn't have relevant results for this metric.

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 480.522s -> 498.187s (3.68%)
Artifact size: 391.37 MiB -> 391.24 MiB (-0.03%)

rust-bors Bot pushed a commit that referenced this pull request Jun 24, 2026
[stable] 1.96.1 release

This prepares 1.96.1 release with:

- [Cargo: fix timeout/retry behavior](rust-lang/cargo#17131)
- [rustc: fix unsoundness in MIR opt](#158214)

Currently targeting this Thursday.

r? me
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. beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. stable-accepted Accepted for backporting to the compiler in the stable channel. stable-nominated Nominated for backporting to the compiler in the stable channel. 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.

Suspected miscompilation with bool as u32

7 participants