|
| 1 | +; RUN: opt %s -analyze -loops | FileCheck -check-prefix=LOOPBEFORE %s |
| 2 | +; RUN: opt %s -dxil-remove-unstructured-loop-exits -o %t.bc |
| 3 | +; RUN: opt %t.bc -S | FileCheck %s |
| 4 | +; RUN: opt %t.bc -analyze -loops | FileCheck -check-prefix=LOOPAFTER %s |
| 5 | + |
| 6 | +; The exiting edge from the latch block of the loop at depth 3 exits to the loop at depth 1. |
| 7 | +; This reproduces the original bug. |
| 8 | +; |
| 9 | +; Loop exits are 'dedicated', one of the LoopSimplifyForm criteria. |
| 10 | + |
| 11 | +; |
| 12 | +; entry |
| 13 | +; | |
| 14 | +; v |
| 15 | +; header.1 --> header.2 --> header.3 --> if.3 -----> exiting.3 |
| 16 | +; ^ ^ ^ | | | |
| 17 | +; | | | v | | |
| 18 | +; | | latch.3 <--- endif.3 <----+ | |
| 19 | +; | | | | |
| 20 | +; | | | v |
| 21 | +; | latch.2 <----------------------------- exit.3.to.2 |
| 22 | +; | | | |
| 23 | +; | +-------- latch.2.exit | |
| 24 | +; | | | |
| 25 | +; | | v |
| 26 | +; | | latch.3.exit |
| 27 | +; | | | |
| 28 | +; | v | |
| 29 | +; latch.1 <-----------------+ |
| 30 | +; | |
| 31 | +; v |
| 32 | +; end |
| 33 | +; |
| 34 | + |
| 35 | + |
| 36 | +; LOOPBEFORE: Loop at depth 1 containing: %header.1<header>,%header.2,%header.3,%if.3,%exiting.3,%endif.3,%latch.3,%latch.3.exit,%exit.3.to.2,%latch.2,%latch.2.exit,%latch.1<latch><exiting> |
| 37 | +; LOOPBEFORE-NEXT: Loop at depth 2 containing: %header.2<header>,%header.3,%if.3,%exiting.3,%endif.3,%latch.3<exiting>,%exit.3.to.2,%latch.2<latch><exiting> |
| 38 | +; LOOPBEFORE-NEXT: Loop at depth 3 containing: %header.3<header>,%if.3,%exiting.3<exiting>,%endif.3,%latch.3<latch><exiting> |
| 39 | +; no more loops expected |
| 40 | +; LOOPBEFORE-NOT: Loop at depth |
| 41 | + |
| 42 | +; LOOPAFTER: Loop at depth 1 containing: %header.1<header>,%header.2,%header.3,%if.3,%exiting.3,%dx.struct_exit.new_exiting,%endif.3,%latch.3,%latch.3.exit,%0,%exit.3.to.2,%dx.struct_exit.new_exiting4,%latch.2,%latch.2.exit,%1,%latch.3.exit.split,%latch.1<latch><exiting> |
| 43 | +; LOOPAFTER-NEXT: Loop at depth 2 containing: %header.2<header>,%header.3,%if.3,%exiting.3,%dx.struct_exit.new_exiting,%endif.3,%latch.3,%latch.3.exit,%0,%exit.3.to.2,%dx.struct_exit.new_exiting4<exiting>,%latch.2<latch><exiting> |
| 44 | +; LOOPAFTER-NEXT: Loop at depth 3 containing: %header.3<header>,%if.3,%exiting.3,%dx.struct_exit.new_exiting<exiting>,%endif.3,%latch.3<latch><exiting> |
| 45 | +; no more loops expected |
| 46 | +; LOOPAFTER-NOT: Loop at depth |
| 47 | + |
| 48 | + |
| 49 | +target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" |
| 50 | +target triple = "dxil-ms-dx" |
| 51 | + |
| 52 | + |
| 53 | +define void @main(i1 %cond) { |
| 54 | +entry: |
| 55 | + br label %header.1 |
| 56 | + |
| 57 | +header.1: |
| 58 | + br label %header.2 |
| 59 | + |
| 60 | +header.2: |
| 61 | + br label %header.3 |
| 62 | + |
| 63 | +header.3: |
| 64 | + br label %if.3 |
| 65 | + |
| 66 | +if.3: |
| 67 | + br i1 %cond, label %exiting.3, label %endif.3 |
| 68 | + |
| 69 | +exiting.3: |
| 70 | + %x3val = add i32 0, 0 |
| 71 | + br i1 %cond, label %exit.3.to.2, label %endif.3 |
| 72 | + |
| 73 | +endif.3: |
| 74 | + br label %latch.3 |
| 75 | + |
| 76 | +latch.3: |
| 77 | + br i1 %cond, label %latch.3.exit, label %header.3 |
| 78 | + |
| 79 | +latch.3.exit: |
| 80 | + br label %latch.1 |
| 81 | + |
| 82 | +latch.2: |
| 83 | + %l2val = phi i32 [ %x3val, %exit.3.to.2 ] |
| 84 | + br i1 %cond, label %latch.2.exit, label %header.2 |
| 85 | + |
| 86 | +latch.2.exit: |
| 87 | + br label %latch.1 |
| 88 | + |
| 89 | +exit.3.to.2: |
| 90 | + br label %latch.2 |
| 91 | + |
| 92 | +latch.1: |
| 93 | + br i1 %cond, label %end, label %header.1 |
| 94 | + |
| 95 | +end: |
| 96 | + ret void |
| 97 | +} |
| 98 | + |
| 99 | + |
| 100 | +; CHECK: define void @main(i1 %cond) { |
| 101 | +; CHECK: entry: |
| 102 | +; CHECK: br label %header.1 |
| 103 | + |
| 104 | +; CHECK: header.1: |
| 105 | +; CHECK: br label %header.2 |
| 106 | + |
| 107 | +; CHECK: header.2: |
| 108 | +; CHECK: br label %header.3 |
| 109 | + |
| 110 | +; CHECK: header.3: |
| 111 | +; CHECK: br label %if.3 |
| 112 | + |
| 113 | +; CHECK: if.3: |
| 114 | +; CHECK: br i1 %cond, label %exiting.3, label %dx.struct_exit.new_exiting |
| 115 | + |
| 116 | +; CHECK: exiting.3: |
| 117 | +; CHECK: %x3val = add i32 0, 0 |
| 118 | +; CHECK: br label %dx.struct_exit.new_exiting |
| 119 | + |
| 120 | +; CHECK: dx.struct_exit.new_exiting: |
| 121 | +; CHECK: %dx.struct_exit.prop1 = phi i1 [ %cond, %exiting.3 ], [ false, %if.3 ] |
| 122 | +; CHECK: %dx.struct_exit.prop = phi i32 [ %x3val, %exiting.3 ], [ 0, %if.3 ] |
| 123 | +; CHECK: br i1 %dx.struct_exit.prop1, label %latch.3.exit, label %endif.3 |
| 124 | + |
| 125 | +; CHECK: endif.3: |
| 126 | +; CHECK: br label %latch.3 |
| 127 | + |
| 128 | +; CHECK: latch.3: |
| 129 | +; CHECK: br i1 %cond, label %latch.3.exit, label %header.3 |
| 130 | + |
| 131 | +; CHECK: latch.3.exit: |
| 132 | +; CHECK: %dx.struct_exit.exit_cond_lcssa = phi i1 [ %dx.struct_exit.prop1, %dx.struct_exit.new_exiting ], [ false, %latch.3 ] |
| 133 | +; CHECK: %dx.struct_exit.val_lcssa = phi i32 [ %dx.struct_exit.prop, %dx.struct_exit.new_exiting ], [ 0, %latch.3 ] |
| 134 | +; CHECK: br i1 %dx.struct_exit.exit_cond_lcssa, label %exit.3.to.2, label %0 |
| 135 | + |
| 136 | +; CHECK: <label>:0 |
| 137 | +; CHECK: br label %dx.struct_exit.new_exiting4 |
| 138 | + |
| 139 | +; CHECK: latch.3.exit.split: |
| 140 | +; CHECK: br label %latch.1 |
| 141 | + |
| 142 | +; CHECK: dx.struct_exit.new_exiting4: |
| 143 | +; CHECK: %dx.struct_exit.prop3 = phi i1 [ true, %0 ], [ false, %exit.3.to.2 ] |
| 144 | +; CHECK: %l2val = phi i32 [ %x3val.lcssa, %exit.3.to.2 ], [ 0, %0 ] |
| 145 | +; CHECK: br i1 %dx.struct_exit.prop3, label %latch.2.exit, label %latch.2 |
| 146 | + |
| 147 | +; CHECK: latch.2: |
| 148 | +; CHECK: br i1 %cond, label %latch.2.exit, label %header.2 |
| 149 | + |
| 150 | +; CHECK: latch.2.exit: |
| 151 | +; CHECK: %dx.struct_exit.exit_cond_lcssa6 = phi i1 [ %dx.struct_exit.prop3, %dx.struct_exit.new_exiting4 ], [ false, %latch.2 ] |
| 152 | +; CHECK: br i1 %dx.struct_exit.exit_cond_lcssa6, label %latch.3.exit.split, label %1 |
| 153 | + |
| 154 | +; CHECK: <label>:1 |
| 155 | +; CHECK: br label %latch.1 |
| 156 | + |
| 157 | +; CHECK: exit.3.to.2: |
| 158 | +; CHECK: %x3val.lcssa = phi i32 [ %dx.struct_exit.val_lcssa, %latch.3.exit ] |
| 159 | +; CHECK: br label %dx.struct_exit.new_exiting4 |
| 160 | + |
| 161 | +; CHECK: latch.1: |
| 162 | +; CHECK: br i1 %cond, label %end, label %header.1 |
| 163 | + |
| 164 | +; CHECK: end: |
| 165 | +; CHECK: ret void |
| 166 | +; CHECK: } |
0 commit comments