forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
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 rust-lang#116531 - cjgillot:nrvo, r=<try>
Fortify and re-enable RNVO MIR opt Fixes rust-lang#111005 Fixes rust-lang#110902 This PR re-enables NRVO opt that had been disabled in rust-lang#111007 To look for RVO opportunities, we walk the MIR backwards from `return` terminators. In addition to the former implementation, we look at all the traversed statements and terminators for writes. If a local is written-to or moved-from, we discard it from the RVO candidates (`assigned_locals` bitset). If we see an indirect write or move, we discard all borrowed locals from candidates. cc `@JakobDegen`
- Loading branch information
Showing
13 changed files
with
379 additions
and
71 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
22 changes: 22 additions & 0 deletions
22
tests/mir-opt/nrvo_miscompile_111005.call.RenameReturnPlace.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,22 @@ | ||
- // MIR for `call` before RenameReturnPlace | ||
+ // MIR for `call` after RenameReturnPlace | ||
|
||
fn call(_1: char) -> char { | ||
let mut _0: char; | ||
let mut _2: char; | ||
|
||
bb0: { | ||
_0 = wrong(_1) -> [return: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
_2 = _1; | ||
_0 = _2; | ||
_2 = wrong(_1) -> [return: bb2, unwind continue]; | ||
} | ||
|
||
bb2: { | ||
return; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
tests/mir-opt/nrvo_miscompile_111005.call_ok.RenameReturnPlace.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,22 @@ | ||
- // MIR for `call_ok` before RenameReturnPlace | ||
+ // MIR for `call_ok` after RenameReturnPlace | ||
|
||
fn call_ok(_1: char) -> char { | ||
let mut _0: char; | ||
let mut _2: char; | ||
|
||
bb0: { | ||
_0 = wrong(_1) -> [return: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
- _2 = wrong(_1) -> [return: bb2, unwind continue]; | ||
+ _0 = wrong(_1) -> [return: bb2, unwind continue]; | ||
} | ||
|
||
bb2: { | ||
- _0 = _2; | ||
return; | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
tests/mir-opt/nrvo_miscompile_111005.indirect.RenameReturnPlace.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,17 @@ | ||
- // MIR for `indirect` before RenameReturnPlace | ||
+ // MIR for `indirect` after RenameReturnPlace | ||
|
||
fn indirect(_1: char) -> char { | ||
let mut _0: char; | ||
let mut _2: char; | ||
let mut _3: &mut char; | ||
|
||
bb0: { | ||
_2 = _1; | ||
_3 = &mut _2; | ||
_0 = _2; | ||
(*_3) = const 'b'; | ||
return; | ||
} | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
tests/mir-opt/nrvo_miscompile_111005.moved.RenameReturnPlace.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,16 @@ | ||
- // MIR for `moved` before RenameReturnPlace | ||
+ // MIR for `moved` after RenameReturnPlace | ||
|
||
fn moved(_1: char) -> char { | ||
let mut _0: char; | ||
let mut _2: char; | ||
let mut _3: char; | ||
|
||
bb0: { | ||
_2 = _1; | ||
_0 = _2; | ||
_3 = move _2; | ||
return; | ||
} | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
tests/mir-opt/nrvo_miscompile_111005.multiple.RenameReturnPlace.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,19 @@ | ||
- // MIR for `multiple` before RenameReturnPlace | ||
+ // MIR for `multiple` after RenameReturnPlace | ||
|
||
fn multiple(_1: char) -> char { | ||
let mut _0: char; | ||
let mut _2: char; | ||
let mut _3: char; | ||
|
||
bb0: { | ||
_2 = _1; | ||
- _3 = _1; | ||
- _0 = _3; | ||
+ _0 = _1; | ||
_0 = _2; | ||
_2 = const 'b'; | ||
return; | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
tests/mir-opt/nrvo_miscompile_111005.multiple_return.RenameReturnPlace.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,25 @@ | ||
- // MIR for `multiple_return` before RenameReturnPlace | ||
+ // MIR for `multiple_return` after RenameReturnPlace | ||
|
||
fn multiple_return(_1: char, _2: bool) -> char { | ||
let mut _0: char; | ||
let mut _3: char; | ||
let mut _4: char; | ||
|
||
bb0: { | ||
switchInt(_2) -> [0: bb1, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_3 = _1; | ||
_0 = _3; | ||
return; | ||
} | ||
|
||
bb2: { | ||
_4 = const 'z'; | ||
_0 = _4; | ||
return; | ||
} | ||
} | ||
|
Oops, something went wrong.