1; RUN: opt < %s -passes='simple-loop-unswitch<nontrivial>' -S 2>&1 | FileCheck %s 2; RUN: opt < %s -passes='loop-mssa(simple-loop-unswitch<nontrivial>)' -S 2>&1 | FileCheck %s 3; 4; Checking that (dead) blocks from inner loop are deleted after unswitch. 5; 6declare void @foo() 7 8; CHECK-LABEL: @Test 9define void @Test(i32) { 10entry: 11 br label %outer 12outer: 13 %oi = phi i32 [ 0, %entry ], [ %oinc, %outer_continue] 14 br label %inner 15inner: 16 %ii = phi i32 [ 0, %outer ], [ %iinc, %continue] 17 call void @foo() 18 switch i32 %0, label %get_out2 [ 19 i32 0, label %continue 20 i32 1, label %case1 21 i32 2, label %get_out 22 ] 23; 24; since we unswitch on the above switch, %case1 and %continue blocks 25; become dead in the original loop 26; 27; CHECK-NOT: case1: 28case1: 29 br label %continue 30; CHECK-NOT: {{^}}continue: 31continue: 32 %iinc = add i32 %ii, 1 33 %icmp = icmp eq i32 %ii, 100 34 br i1 %icmp, label %inner, label %outer_continue 35 36outer_continue: 37 %oinc = add i32 %oi, 1 38 %ocmp = icmp eq i32 %oi, 100 39 br i1 %ocmp, label %outer, label %get_out 40 41get_out: 42 ret void 43get_out2: 44 unreachable 45} 46 47; 48; This comes from PR38778 49; CHECK-LABEL: @Test2 50define void @Test2(i32, i1 %arg) { 51header: 52 br label %loop 53loop: 54 switch i32 %0, label %continue [ 55 i32 -2147483648, label %check 56 i32 98, label %guarded1 57 i32 99, label %guarded2 58 ] 59; CHECK-NOT: {{^}}guarded1: 60guarded1: 61 br i1 %arg, label %continue, label %leave 62guarded2: 63 br label %continue 64check: 65 %val = add i32 0, 1 66 br i1 %arg, label %continue, label %leave 67continue: 68 br label %loop 69leave: 70 %local = phi i32 [ 0, %guarded1 ], [ %val, %check ] 71 ret void 72} 73 74; 75; Yet another test from PR38778 76; 77; CHECK-LABEL: @Test3 78define void @Test3(i32, i1 %arg) { 79header: 80 br label %outer 81outer: 82 %bad_input.i = icmp eq i32 %0, -2147483648 83 br label %inner 84inner: 85 br i1 %bad_input.i, label %overflow, label %switchme 86overflow: 87 br label %continue 88switchme: 89 switch i32 %0, label %continue [ 90 i32 88, label %go_out 91 i32 99, label %case2 92 ] 93; CHECK-NOT: {{^}}case2: 94case2: 95 br label %continue 96continue: 97 %local_11_92 = phi i32 [ 0, %switchme ], [ 18, %case2 ], [ 0, %overflow ] 98 br i1 %arg, label %outer, label %inner 99go_out: 100 unreachable 101} 102