Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -simple-loop-unswitch -enable-nontrivial-unswitch -S 2>&1 | FileCheck %s |
| 2 | ; RUN: opt < %s -passes=unswitch -enable-nontrivial-unswitch -S 2>&1 | FileCheck %s |
| 3 | ; |
| 4 | ; Checking that (dead) blocks from inner loop are deleted after unswitch. |
| 5 | ; |
| 6 | declare void @foo() |
| 7 | |
| 8 | ; CHECK-LABEL: @Test |
| 9 | define void @Test(i32) { |
| 10 | entry: |
| 11 | br label %outer |
| 12 | outer: |
| 13 | %oi = phi i32 [ 0, %entry ], [ %oinc, %outer_continue] |
| 14 | br label %inner |
| 15 | inner: |
| 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: |
| 28 | case1: |
| 29 | br label %continue |
| 30 | ; CHECK-NOT: {{^}}continue: |
| 31 | continue: |
| 32 | %iinc = add i32 %ii, 1 |
| 33 | %icmp = icmp eq i32 %ii, 100 |
| 34 | br i1 %icmp, label %inner, label %outer_continue |
| 35 | |
| 36 | outer_continue: |
| 37 | %oinc = add i32 %oi, 1 |
| 38 | %ocmp = icmp eq i32 %oi, 100 |
| 39 | br i1 %ocmp, label %outer, label %get_out |
| 40 | |
| 41 | get_out: |
| 42 | ret void |
| 43 | get_out2: |
| 44 | unreachable |
| 45 | } |
| 46 | |
| 47 | ; |
| 48 | ; This comes from PR38778 |
| 49 | ; CHECK-LABEL: @Test2 |
| 50 | define void @Test2(i32) { |
| 51 | header: |
| 52 | br label %loop |
| 53 | loop: |
| 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: |
| 60 | guarded1: |
| 61 | br i1 undef, label %continue, label %leave |
| 62 | guarded2: |
| 63 | br label %continue |
| 64 | check: |
| 65 | %val = add i32 0, 1 |
| 66 | br i1 undef, label %continue, label %leave |
| 67 | continue: |
| 68 | br label %loop |
| 69 | leave: |
| 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 |
| 78 | define void @Test3(i32) { |
| 79 | header: |
| 80 | br label %outer |
| 81 | outer: |
| 82 | %bad_input.i = icmp eq i32 %0, -2147483648 |
| 83 | br label %inner |
| 84 | inner: |
| 85 | br i1 %bad_input.i, label %overflow, label %switchme |
| 86 | overflow: |
| 87 | br label %continue |
| 88 | switchme: |
| 89 | switch i32 %0, label %continue [ |
| 90 | i32 88, label %go_out |
| 91 | i32 99, label %case2 |
| 92 | ] |
| 93 | ; CHECK-NOT: {{^}}case2: |
| 94 | case2: |
| 95 | br label %continue |
| 96 | continue: |
| 97 | %local_11_92 = phi i32 [ 0, %switchme ], [ 18, %case2 ], [ 0, %overflow ] |
| 98 | br i1 undef, label %outer, label %inner |
| 99 | go_out: |
| 100 | unreachable |
| 101 | } |