102 lines · plain
1; RUN: opt < %s -passes='simple-loop-unswitch<nontrivial>' -S 2>&1 | FileCheck %s2; RUN: opt < %s -passes='loop-mssa(simple-loop-unswitch<nontrivial>)' -S 2>&1 | FileCheck %s3;4; Checking that (dead) blocks from inner loop are deleted after unswitch.5;6declare void @foo()7 8; CHECK-LABEL: @Test9define void @Test(i32) {10entry:11 br label %outer12outer:13 %oi = phi i32 [ 0, %entry ], [ %oinc, %outer_continue]14 br label %inner15inner:16 %ii = phi i32 [ 0, %outer ], [ %iinc, %continue]17 call void @foo()18 switch i32 %0, label %get_out2 [19 i32 0, label %continue20 i32 1, label %case121 i32 2, label %get_out22 ]23;24; since we unswitch on the above switch, %case1 and %continue blocks25; become dead in the original loop26;27; CHECK-NOT: case1:28case1:29 br label %continue30; CHECK-NOT: {{^}}continue:31continue:32 %iinc = add i32 %ii, 133 %icmp = icmp eq i32 %ii, 10034 br i1 %icmp, label %inner, label %outer_continue35 36outer_continue:37 %oinc = add i32 %oi, 138 %ocmp = icmp eq i32 %oi, 10039 br i1 %ocmp, label %outer, label %get_out40 41get_out:42 ret void43get_out2:44 unreachable45}46 47;48; This comes from PR3877849; CHECK-LABEL: @Test250define void @Test2(i32, i1 %arg) {51header:52 br label %loop53loop:54 switch i32 %0, label %continue [55 i32 -2147483648, label %check56 i32 98, label %guarded157 i32 99, label %guarded258 ]59; CHECK-NOT: {{^}}guarded1:60guarded1:61 br i1 %arg, label %continue, label %leave62guarded2:63 br label %continue64check:65 %val = add i32 0, 166 br i1 %arg, label %continue, label %leave67continue:68 br label %loop69leave:70 %local = phi i32 [ 0, %guarded1 ], [ %val, %check ]71 ret void72}73 74;75; Yet another test from PR3877876;77; CHECK-LABEL: @Test378define void @Test3(i32, i1 %arg) {79header:80 br label %outer81outer:82 %bad_input.i = icmp eq i32 %0, -214748364883 br label %inner84inner:85 br i1 %bad_input.i, label %overflow, label %switchme86overflow:87 br label %continue88switchme:89 switch i32 %0, label %continue [90 i32 88, label %go_out91 i32 99, label %case292 ]93; CHECK-NOT: {{^}}case2:94case2:95 br label %continue96continue:97 %local_11_92 = phi i32 [ 0, %switchme ], [ 18, %case2 ], [ 0, %overflow ]98 br i1 %arg, label %outer, label %inner99go_out:100 unreachable101}102