-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Also consider call and yield as MIR SSA. #113915
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 21 additions & 0 deletions
21
tests/mir-opt/copy-prop/calls.multiple_edges.CopyProp.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,21 @@ | ||
- // MIR for `multiple_edges` before CopyProp | ||
+ // MIR for `multiple_edges` after CopyProp | ||
|
||
fn multiple_edges(_1: bool) -> u8 { | ||
let mut _0: u8; | ||
let mut _2: u8; | ||
|
||
bb0: { | ||
switchInt(_1) -> [1: bb1, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_2 = dummy(const 13_u8) -> [return: bb2, unwind continue]; | ||
} | ||
|
||
bb2: { | ||
_0 = _2; | ||
return; | ||
} | ||
} | ||
|
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 `nrvo` before CopyProp | ||
+ // MIR for `nrvo` after CopyProp | ||
|
||
fn nrvo() -> u8 { | ||
let mut _0: u8; | ||
let _1: u8; | ||
scope 1 { | ||
- debug y => _1; | ||
+ debug y => _0; | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_1); | ||
- _1 = dummy(const 5_u8) -> [return: bb1, unwind continue]; | ||
+ _0 = dummy(const 5_u8) -> [return: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
- _0 = _1; | ||
- StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
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,43 @@ | ||
// Check that CopyProp does propagate return values of call terminators. | ||
// unit-test: CopyProp | ||
// needs-unwind | ||
|
||
#![feature(custom_mir, core_intrinsics)] | ||
use std::intrinsics::mir::*; | ||
|
||
#[inline(never)] | ||
fn dummy(x: u8) -> u8 { | ||
x | ||
} | ||
|
||
// EMIT_MIR calls.nrvo.CopyProp.diff | ||
fn nrvo() -> u8 { | ||
let y = dummy(5); // this should get NRVO | ||
y | ||
} | ||
|
||
// EMIT_MIR calls.multiple_edges.CopyProp.diff | ||
#[custom_mir(dialect = "runtime", phase = "initial")] | ||
fn multiple_edges(t: bool) -> u8 { | ||
mir! { | ||
let x: u8; | ||
{ | ||
match t { true => bbt, _ => ret } | ||
} | ||
bbt = { | ||
Call(x = dummy(13), ret) | ||
} | ||
ret = { | ||
// `x` is not assigned on the `bb0 -> ret` edge, | ||
// so should not be marked as SSA for merging with `_0`. | ||
RET = x; | ||
Return() | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
// Make sure the function actually gets instantiated. | ||
nrvo(); | ||
multiple_edges(false); | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmiasko Following the discussion on #116454 (comment), I reuse
DefLocation::Body
for the terminators. Do you agree with this conclusion?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried fixing the handling of call terminators in
DefLocation::dominates
and in retrospect your earlier approach with an additional variant turned out much simpler (reusingDefLocation::Body
requiresDefLocation::dominates
to access basic blocks and that gets quite inconvenient). Thus, I would propose something along the lines of abd4ad1.I am not sure if you are still planning to address this as part of this pull request or not. Either way seems fine to me, including leaving
DefLocation::Body
as is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So let's go small steps. This PR as-is, then abd4ad1 in a second PR.