Skip to content

Commit

Permalink
Update the test case for SimplifyCfg-after-unreachable-enum-branching
Browse files Browse the repository at this point in the history
  • Loading branch information
DianQK committed Mar 9, 2024
1 parent 1b13179 commit 2b156ba
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
let mut _0: u8;

bb0: {
- switchInt(_1) -> [0: bb1, 255: bb2, otherwise: bb3];
+ switchInt(_1) -> [0: bb1, 255: bb1, otherwise: bb2];
- switchInt(_1) -> [0: bb3, 1: bb2, 255: bb3, otherwise: bb4];
+ switchInt(_1) -> [0: bb2, 1: bb1, 255: bb2, otherwise: bb3];
}

bb1: {
unreachable;
}

bb2: {
- unreachable;
- _0 = const 1_u8;
- return;
- }
-
- bb2: {
_0 = const 2_u8;
return;
}

- bb3: {
+ bb2: {
unreachable;
}

- bb4: {
+ bb3: {
_0 = _1;
return;
}
Expand Down
52 changes: 52 additions & 0 deletions tests/mir-opt/simplify_dead_blocks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//@ unit-test: SimplifyCfg-after-unreachable-enum-branching
#![feature(custom_mir, core_intrinsics)]
#![crate_type = "lib"]

use std::intrinsics::mir::*;

// Check that we correctly cleaned up the dead BB.
// EMIT_MIR simplify_dead_blocks.assert_nonzero_nonmax.SimplifyCfg-after-unreachable-enum-branching.diff
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
pub unsafe fn assert_nonzero_nonmax(x: u8) -> u8 {
// CHECK-LABEL: fn assert_nonzero_nonmax(
// CHECK: bb0: {
// CHECK-NEXT: switchInt({{.*}}) -> [0: [[unreachable:bb.*]], 1: [[retblock2:bb.*]], 255: [[unreachable:bb.*]], otherwise: [[retblock:bb.*]]];
// CHECK-NEXT: }
// CHECK-NOT: _0 = const 1_u8;
// CHECK: [[retblock2]]: {
// CHECK-NEXT: _0 = const 2_u8;
// CHECK-NEXT: return;
// CHECK-NEXT: }
// CHECK: [[unreachable]]: {
// CHECK-NEXT: unreachable;
// CHECK-NEXT: }
// CHECK: [[retblock]]: {
// CHECK-NEXT: _0 = _1;
// CHECK-NEXT: return;
// CHECK-NEXT: }
mir!(
{
match x {
0 => unreachable,
1 => retblock2,
u8::MAX => unreachable,
_ => retblock,
}
}
deadRetblock1 = {
RET = 1;
Return()
}
retblock2 = {
RET = 2;
Return()
}
unreachable = {
Unreachable()
}
retblock = {
RET = x;
Return()
}
)
}
31 changes: 0 additions & 31 deletions tests/mir-opt/simplify_duplicate_unreachable_blocks.rs

This file was deleted.

0 comments on commit 2b156ba

Please sign in to comment.