-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #123602 - cjgillot:gvn-borrowed, r=<try>
Account for immutably borrowed locals in MIR copy-prop and GVN For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise. This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes. This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB. r? `@ghost` for perf
- Loading branch information
Showing
27 changed files
with
568 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
Function name: issue_83601::main | ||
Raw bytes (21): 0x[01, 01, 01, 05, 09, 03, 01, 06, 01, 02, 1c, 05, 03, 09, 01, 1c, 02, 02, 05, 03, 02] | ||
Raw bytes (21): 0x[01, 01, 01, 05, 00, 03, 01, 06, 01, 02, 1c, 05, 03, 09, 01, 1c, 02, 02, 05, 03, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 1 | ||
- expression 0 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 0 operands: lhs = Counter(1), rhs = Zero | ||
Number of file 0 mappings: 3 | ||
- Code(Counter(0)) at (prev + 6, 1) to (start + 2, 28) | ||
- Code(Counter(1)) at (prev + 3, 9) to (start + 1, 28) | ||
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 3, 2) | ||
= (c1 - c2) | ||
= (c1 - Zero) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
tests/mir-opt/copy-prop/borrowed_local.borrowed.CopyProp.panic-abort.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
- // MIR for `borrowed` before CopyProp | ||
+ // MIR for `borrowed` after CopyProp | ||
|
||
fn borrowed(_1: u32) -> bool { | ||
let mut _0: bool; | ||
let mut _2: u32; | ||
let mut _3: &u32; | ||
|
||
bb0: { | ||
- _2 = _1; | ||
_3 = &_1; | ||
_0 = opaque::<&u32>(_3) -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
- _0 = opaque::<u32>(_2) -> [return: bb2, unwind unreachable]; | ||
+ _0 = opaque::<u32>(_1) -> [return: bb2, unwind unreachable]; | ||
} | ||
|
||
bb2: { | ||
return; | ||
} | ||
} | ||
|
Oops, something went wrong.