Kyle Butt | 0846e56 | 2016-10-11 20:36:43 +0000 | [diff] [blame^] | 1 | ; RUN: llc -O2 -o - %s | FileCheck %s |
| 2 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 3 | target triple = "x86_64-unknown-linux-gnu" |
| 4 | |
| 5 | ; Function Attrs: nounwind uwtable |
| 6 | ; CHECK-LABEL: tail_dup_merge_loops |
| 7 | ; CHECK: # %entry |
| 8 | ; CHECK-NOT: # %{{[a-zA-Z_]+}} |
| 9 | ; CHECK: # %inner_loop_exit |
| 10 | ; CHECK-NOT: # %{{[a-zA-Z_]+}} |
| 11 | ; CHECK: # %inner_loop_latch |
| 12 | ; CHECK-NOT: # %{{[a-zA-Z_]+}} |
| 13 | ; CHECK: # %inner_loop_test |
| 14 | ; CHECK-NOT: # %{{[a-zA-Z_]+}} |
| 15 | ; CHECK: # %exit |
| 16 | define void @tail_dup_merge_loops(i32 %a, i8* %b, i8* %c) local_unnamed_addr #0 { |
| 17 | entry: |
| 18 | %notlhs674.i = icmp eq i32 %a, 0 |
| 19 | br label %outer_loop_top |
| 20 | |
| 21 | outer_loop_top: ; preds = %inner_loop_exit, %entry |
| 22 | %dst.0.ph.i = phi i8* [ %b, %entry ], [ %scevgep679.i, %inner_loop_exit ] |
| 23 | br i1 %notlhs674.i, label %exit, label %inner_loop_preheader |
| 24 | |
| 25 | inner_loop_preheader: ; preds = %outer_loop_top |
| 26 | br label %inner_loop_top |
| 27 | |
| 28 | inner_loop_top: ; preds = %inner_loop_latch, %inner_loop_preheader |
| 29 | %dst.0.i = phi i8* [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ] |
| 30 | %var = load i8, i8* %dst.0.i |
| 31 | %tobool1.i = icmp slt i8 %var, 0 |
| 32 | br label %inner_loop_test |
| 33 | |
| 34 | inner_loop_test: ; preds = %inner_loop_top |
| 35 | br i1 %tobool1.i, label %inner_loop_exit, label %inner_loop_latch |
| 36 | |
| 37 | inner_loop_exit: ; preds = %inner_loop_test |
| 38 | %scevgep.i = getelementptr i8, i8* %dst.0.i, i64 1 |
| 39 | %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 0 |
| 40 | br label %outer_loop_top |
| 41 | |
| 42 | inner_loop_latch: ; preds = %inner_loop_test |
| 43 | %cmp75.i = icmp ult i8* %dst.0.i, %c |
| 44 | %inc = getelementptr i8, i8* %dst.0.i, i64 2 |
| 45 | br label %inner_loop_top |
| 46 | |
| 47 | exit: ; preds = %outer_loop_top |
| 48 | ret void |
| 49 | } |
| 50 | |
| 51 | @.str.6 = external unnamed_addr constant [23 x i8], align 1 |
| 52 | |
| 53 | ; There is an erroneus check in LoopBase::addBasicBlockToLoop(), where it |
| 54 | ; assumes that the header block for a loop is unique. |
| 55 | ; For most of compilation this assumption is true, but during layout we allow |
| 56 | ; this assumption to be violated. The following code will trigger the bug: |
| 57 | |
| 58 | ; The loops in question is eventually headed by the block shared_loop_header |
| 59 | ; |
| 60 | ; During layout The block labeled outer_loop_header gets tail-duplicated into |
| 61 | ; outer_loop_latch, and into shared_preheader, and then removed. This leaves |
| 62 | ; shared_loop_header as the header of both loops. The end result |
| 63 | ; is that there are 2 valid loops, and that they share a header. If we re-ran |
| 64 | ; the loop analysis, it would classify this as a single loop. |
| 65 | ; So far this is fine as far as layout is concerned. |
| 66 | ; After layout we tail merge blocks merge_other and merge_predecessor_split. |
| 67 | ; We do this even though they share only a single instruction, because |
| 68 | ; merge_predecessor_split falls through to their shared successor: |
| 69 | ; outer_loop_latch. |
| 70 | ; The rest of the blocks in the function are noise unfortunately. Bugpoint |
| 71 | ; couldn't shrink the test any further. |
| 72 | |
| 73 | ; CHECK-LABEL: loop_shared_header |
| 74 | ; CHECK: # %entry |
| 75 | ; CHECK: # %shared_preheader |
| 76 | ; CHECK: # %shared_loop_header |
| 77 | ; CHECK: # %inner_loop_body |
| 78 | ; CHECK: # %merge_predecessor_split |
| 79 | ; CHECK: # %outer_loop_latch |
| 80 | ; CHECK: # %outer_loop_latch |
| 81 | ; CHECK: # %cleanup |
| 82 | define i32 @loop_shared_header(i8* %exe, i32 %exesz, i32 %headsize, i32 %min, i32 %wwprva, i32 %e_lfanew, i8* readonly %wwp, i32 %wwpsz, i16 zeroext %sects) local_unnamed_addr #0 { |
| 83 | entry: |
| 84 | %0 = load i32, i32* undef, align 4 |
| 85 | %mul = shl nsw i32 %0, 2 |
| 86 | br i1 undef, label %if.end19, label %cleanup |
| 87 | |
| 88 | if.end19: ; preds = %entry |
| 89 | %conv = zext i32 %mul to i64 |
| 90 | %call = tail call i8* @cli_calloc(i64 %conv, i64 1) |
| 91 | %1 = icmp eq i32 %exesz, 0 |
| 92 | %notrhs = icmp eq i32 %0, 0 |
| 93 | %or.cond117.not = or i1 %1, %notrhs |
| 94 | %or.cond202 = or i1 %or.cond117.not, undef |
| 95 | %cmp35 = icmp ult i8* undef, %exe |
| 96 | %or.cond203 = or i1 %or.cond202, %cmp35 |
| 97 | br i1 %or.cond203, label %cleanup, label %if.end50 |
| 98 | |
| 99 | if.end50: ; preds = %if.end19 |
| 100 | tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i32 1, i1 false) |
| 101 | %cmp1.i.i = icmp ugt i32 %mul, 3 |
| 102 | br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391 |
| 103 | |
| 104 | shared_preheader: ; preds = %if.end50 |
| 105 | br label %outer_loop_header |
| 106 | |
| 107 | outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader |
| 108 | %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ] |
| 109 | %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ] |
| 110 | %2 = icmp eq i32 undef, 0 |
| 111 | br i1 %2, label %while.cond.us1412.i, label %shared_loop_header |
| 112 | |
| 113 | while.cond.us1412.i: ; preds = %outer_loop_header |
| 114 | %.pre.i = add i8 %bits.1.i, -1 |
| 115 | %tobool2.us1420.i = icmp eq i8 %.pre.i, 0 |
| 116 | %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i |
| 117 | br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup |
| 118 | |
| 119 | if.end41.us1436.i: ; preds = %while.cond.us1412.i |
| 120 | unreachable |
| 121 | |
| 122 | shared_loop_header: ; preds = %dup_early2, %dup_early1 |
| 123 | %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ] |
| 124 | %cmp3.i1172.i = icmp ult i8* undef, %call |
| 125 | br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body |
| 126 | |
| 127 | inner_loop_body: ; preds = %shared_loop_header |
| 128 | %3 = icmp slt i32 undef, 0 |
| 129 | br i1 %3, label %if.end96.i, label %shared_loop_header |
| 130 | |
| 131 | dead_block: ; preds = %inner_loop_body |
| 132 | %cmp75.i = icmp ult i8* %dst.0.i, undef |
| 133 | br label %shared_loop_header |
| 134 | |
| 135 | if.end96.i: ; preds = %inner_loop_body |
| 136 | %cmp97.i = icmp ugt i32 undef, 2 |
| 137 | br i1 %cmp97.i, label %if.then99.i, label %if.end287.i |
| 138 | |
| 139 | if.then99.i: ; preds = %if.end96.i |
| 140 | tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef) |
| 141 | br label %cleanup |
| 142 | |
| 143 | if.end287.i: ; preds = %if.end96.i |
| 144 | %cmp291.i = icmp ne i32 undef, 1 |
| 145 | %conv294.i = select i1 %cmp291.i, i16 4, i16 3 |
| 146 | br i1 undef, label %if.end308.i, label %outer_loop_latch |
| 147 | |
| 148 | if.end308.i: ; preds = %if.end287.i |
| 149 | br i1 undef, label %if.end335.i, label %merge_predecessor_split |
| 150 | |
| 151 | merge_predecessor_split: ; preds = %if.end308.i |
| 152 | %4 = bitcast i8* undef to i32* |
| 153 | br label %outer_loop_latch |
| 154 | |
| 155 | if.end335.i: ; preds = %if.end308.i |
| 156 | br i1 undef, label %outer_loop_latch, label %merge_other |
| 157 | |
| 158 | merge_other: ; preds = %if.end335.i |
| 159 | br label %outer_loop_latch |
| 160 | |
| 161 | outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i |
| 162 | %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ] |
| 163 | %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ] |
| 164 | %5 = add i16 %backsize.0.i, -1 |
| 165 | %6 = zext i16 %5 to i64 |
| 166 | %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1 |
| 167 | %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6 |
| 168 | br label %outer_loop_header |
| 169 | |
| 170 | wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header |
| 171 | unreachable |
| 172 | |
| 173 | wunpsect.exit.thread.loopexit391: ; preds = %if.end50 |
| 174 | unreachable |
| 175 | |
| 176 | cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry |
| 177 | %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ] |
| 178 | ret i32 %retval.0 |
| 179 | } |
| 180 | |
| 181 | ; Function Attrs: nounwind |
| 182 | declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0 |
| 183 | |
| 184 | ; Function Attrs: nounwind |
| 185 | declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0 |
| 186 | |
| 187 | ; Function Attrs: argmemonly nounwind |
| 188 | declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i32, i1) #1 |
| 189 | attributes #0 = { nounwind } |
| 190 | attributes #1 = { argmemonly nounwind } |