Avoid loop_match self-assignment in MIR lowering#155186
Avoid loop_match self-assignment in MIR lowering#155186rust-bors[bot] merged 3 commits intorust-lang:mainfrom
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
rustbot has assigned @jdonszelmann. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Just conceptually, would it not be better to remove the assignment completely? Or does that not work? I've previously tried to change the code so that the assignment does not get introduced, but that did not work out (it would, from memory, require overhauling a whole bunch of code). |
I did consider this approach at first, but I was worried that it might have a fairly significant impact on MIR semantics. Once |
|
Additionally, I also considered the performance impact. I compared the LLVM IR generated by the compiler for |
|
r? @folkertdev |
I'm sceptical of this if the original MIR had a r? WaffleLapkin do you know, or else who should we ask about this? At a high level the fix does make sense to me, and the tests look good, so |
|
|
This comment has been minimized.
This comment has been minimized.
e347227 to
52bd93d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
There was a problem hiding this comment.
This seems fine to me, unless Waffle has lingering concerns. The copy should just be cleaned up by later MIR passes, or in any case by LLVM.
Linking for posterity #t-compiler/mir-opts > Semantic of assignment.
|
@bors r=folkertdev,WaffleLapkin |
…uwer Rollup of 9 pull requests Successful merges: - #149637 (Do not run jump-threading for GPUs) - #154971 (Verify that penultimate segment of enum variant path refers to enum if it has args) - #155186 (Avoid loop_match self-assignment in MIR lowering) - #155948 (Fix order-dependent visibility diagnostics) - #156001 (ssa-range-prop: fix ICE when encountering self-domiating bb) - #155600 (Adds a couple UI tests for polonius) - #155995 (-Zembed-source: also embed external source) - #156019 (Feed cleanups) - #156031 (Return a single diagnostic from `lex_token_trees`.)
Rollup merge of #155186 - cijiugechu:fix/loop-match-no-self-assign, r=folkertdev,WaffleLapkin Avoid loop_match self-assignment in MIR lowering Transform ``` bb2: { PlaceMention(_1); _1 = copy _1; goto -> bb7; } ``` to ``` bb2: { PlaceMention(_1); _4 = copy _1; _1 = copy _4; goto -> bb7; } ``` Closes #143806 <details> <summary>Previous MIR</summary> ``` fn helper() -> u8 { let mut _0: u8; let mut _1: u8; let mut _2: !; let mut _3: !; scope 1 { debug state => _1; } bb0: { StorageLive(_1); _1 = const 0_u8; FakeRead(ForLet(None), _1); StorageLive(_2); goto -> bb1; } bb1: { falseUnwind -> [real: bb2, unwind: bb11]; } bb2: { PlaceMention(_1); _1 = copy _1; goto -> bb7; } bb3: { FakeRead(ForMatchedPlace(None), _1); unreachable; } bb4: { unreachable; } bb5: { goto -> bb6; } bb6: { goto -> bb8; } bb7: { goto -> bb8; } bb8: { goto -> bb1; } bb9: { unreachable; } bb10: { StorageDead(_2); StorageDead(_1); return; } bb11 (cleanup): { resume; } } ``` </details> <details> <summary>Current MIR</summary> ``` fn helper() -> u8 { let mut _0: u8; let mut _1: u8; let mut _2: !; let mut _3: !; let mut _4: u8; scope 1 { debug state => _1; } bb0: { StorageLive(_1); _1 = const 0_u8; FakeRead(ForLet(None), _1); StorageLive(_2); goto -> bb1; } bb1: { falseUnwind -> [real: bb2, unwind: bb11]; } bb2: { PlaceMention(_1); _4 = copy _1; _1 = copy _4; goto -> bb7; } bb3: { FakeRead(ForMatchedPlace(None), _1); unreachable; } bb4: { unreachable; } bb5: { goto -> bb6; } bb6: { goto -> bb8; } bb7: { goto -> bb8; } bb8: { goto -> bb1; } bb9: { unreachable; } bb10: { StorageDead(_2); StorageDead(_1); return; } bb11 (cleanup): { resume; } } ``` </details>
Transform
to
Closes #143806
Previous MIR
Current MIR