-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #113915 - cjgillot:ssa-call, r=tmiasko
Also consider call and yield as MIR SSA. The SSA analysis on MIR only considered `Assign` statements as defining a SSA local. This PR adds assignments as part of a `Call` or `Yield` terminator in that category. This mainly allows to perform CopyProp on a call return place. The only subtlety is in the dominance property: the assignment is only complete at the beginning of the target block.
- Loading branch information
Showing
13 changed files
with
224 additions
and
124 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
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.