-
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.
Skip threading over no-op SetDiscriminant.
- Loading branch information
Showing
4 changed files
with
146 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
- // MIR for `f` before JumpThreading | ||
+ // MIR for `f` after JumpThreading | ||
|
||
fn f() -> usize { | ||
let mut _0: usize; | ||
let mut _1: isize; | ||
let mut _2: E<char>; | ||
|
||
bb0: { | ||
_2 = E::<char>::A; | ||
discriminant(_2) = 1; | ||
_1 = discriminant(_2); | ||
switchInt(_1) -> [0: bb1, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_0 = const 0_usize; | ||
return; | ||
} | ||
|
||
bb2: { | ||
_0 = const 1_usize; | ||
return; | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
tests/mir-opt/set_no_discriminant.generic.JumpThreading.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,26 @@ | ||
- // MIR for `generic` before JumpThreading | ||
+ // MIR for `generic` after JumpThreading | ||
|
||
fn generic() -> usize { | ||
let mut _0: usize; | ||
let mut _1: isize; | ||
let mut _2: E<T>; | ||
|
||
bb0: { | ||
_2 = E::<T>::A; | ||
discriminant(_2) = 1; | ||
_1 = discriminant(_2); | ||
switchInt(_1) -> [0: bb1, otherwise: bb2]; | ||
} | ||
|
||
bb1: { | ||
_0 = const 0_usize; | ||
return; | ||
} | ||
|
||
bb2: { | ||
_0 = const 1_usize; | ||
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,74 @@ | ||
// `SetDiscriminant` does not actually write anything if the chosen variant is the untagged variant | ||
// of a niche encoding. Verify that we do not thread over this case. | ||
// unit-test: JumpThreading | ||
|
||
#![feature(custom_mir)] | ||
#![feature(core_intrinsics)] | ||
|
||
use std::intrinsics::mir::*; | ||
|
||
enum E<T> { | ||
A, | ||
B(T), | ||
} | ||
|
||
// EMIT_MIR set_no_discriminant.f.JumpThreading.diff | ||
#[custom_mir(dialect = "runtime")] | ||
pub fn f() -> usize { | ||
// CHECK-LABEL: fn f( | ||
// CHECK-NOT: goto | ||
mir!( | ||
let a: isize; | ||
let e: E<char>; | ||
{ | ||
e = E::A; | ||
SetDiscriminant(e, 1); | ||
a = Discriminant(e); | ||
match a { | ||
0 => bb0, | ||
_ => bb1, | ||
} | ||
} | ||
bb0 = { | ||
RET = 0; | ||
Return() | ||
} | ||
bb1 = { | ||
RET = 1; | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
// EMIT_MIR set_no_discriminant.generic.JumpThreading.diff | ||
#[custom_mir(dialect = "runtime")] | ||
pub fn generic<T>() -> usize { | ||
// CHECK-LABEL: fn generic( | ||
// CHECK-NOT: goto | ||
mir!( | ||
let a: isize; | ||
let e: E<T>; | ||
{ | ||
e = E::A; | ||
SetDiscriminant(e, 1); | ||
a = Discriminant(e); | ||
match a { | ||
0 => bb0, | ||
_ => bb1, | ||
} | ||
} | ||
bb0 = { | ||
RET = 0; | ||
Return() | ||
} | ||
bb1 = { | ||
RET = 1; | ||
Return() | ||
} | ||
) | ||
} | ||
|
||
fn main() { | ||
assert_eq!(f(), 0); | ||
assert_eq!(generic::<char>(), 0); | ||
} |