1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s 3 4; Function Attrs: nounwind uwtable 5define void @tail_dup_merge_loops(i32 %a, i8* %b, i8* %c) local_unnamed_addr #0 { 6; CHECK-LABEL: tail_dup_merge_loops: 7; CHECK: # %bb.0: # %entry 8; CHECK-NEXT: jmp .LBB0_1 9; CHECK-NEXT: .p2align 4, 0x90 10; CHECK-NEXT: .LBB0_3: # %inner_loop_exit 11; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1 12; CHECK-NEXT: incq %rsi 13; CHECK-NEXT: .LBB0_1: # %outer_loop_top 14; CHECK-NEXT: # =>This Loop Header: Depth=1 15; CHECK-NEXT: # Child Loop BB0_4 Depth 2 16; CHECK-NEXT: testl %edi, %edi 17; CHECK-NEXT: je .LBB0_5 18; CHECK-NEXT: .p2align 4, 0x90 19; CHECK-NEXT: # %bb.2: # %inner_loop_top 20; CHECK-NEXT: # in Loop: Header=BB0_1 Depth=1 21; CHECK-NEXT: cmpb $0, (%rsi) 22; CHECK-NEXT: js .LBB0_3 23; CHECK-NEXT: .LBB0_4: # %inner_loop_latch 24; CHECK-NEXT: # Parent Loop BB0_1 Depth=1 25; CHECK-NEXT: # => This Inner Loop Header: Depth=2 26; CHECK-NEXT: addq $2, %rsi 27; CHECK-NEXT: cmpb $0, (%rsi) 28; CHECK-NEXT: jns .LBB0_4 29; CHECK-NEXT: jmp .LBB0_3 30; CHECK-NEXT: .LBB0_5: # %exit 31; CHECK-NEXT: retq 32entry: 33 %notlhs674.i = icmp eq i32 %a, 0 34 br label %outer_loop_top 35 36outer_loop_top: ; preds = %inner_loop_exit, %entry 37 %dst.0.ph.i = phi i8* [ %b, %entry ], [ %scevgep679.i, %inner_loop_exit ] 38 br i1 %notlhs674.i, label %exit, label %inner_loop_preheader 39 40inner_loop_preheader: ; preds = %outer_loop_top 41 br label %inner_loop_top 42 43inner_loop_top: ; preds = %inner_loop_latch, %inner_loop_preheader 44 %dst.0.i = phi i8* [ %inc, %inner_loop_latch ], [ %dst.0.ph.i, %inner_loop_preheader ] 45 %var = load i8, i8* %dst.0.i 46 %tobool1.i = icmp slt i8 %var, 0 47 br label %inner_loop_test 48 49inner_loop_test: ; preds = %inner_loop_top 50 br i1 %tobool1.i, label %inner_loop_exit, label %inner_loop_latch 51 52inner_loop_exit: ; preds = %inner_loop_test 53 %scevgep.i = getelementptr i8, i8* %dst.0.i, i64 1 54 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 0 55 br label %outer_loop_top 56 57inner_loop_latch: ; preds = %inner_loop_test 58 %cmp75.i = icmp ult i8* %dst.0.i, %c 59 %inc = getelementptr i8, i8* %dst.0.i, i64 2 60 br label %inner_loop_top 61 62exit: ; preds = %outer_loop_top 63 ret void 64} 65 66@.str.6 = external unnamed_addr constant [23 x i8], align 1 67 68; There is an erroneus check in LoopBase::addBasicBlockToLoop(), where it 69; assumes that the header block for a loop is unique. 70; For most of compilation this assumption is true, but during layout we allow 71; this assumption to be violated. The following code will trigger the bug: 72 73; The loops in question is eventually headed by the block shared_loop_header 74; 75; During layout The block labeled outer_loop_header gets tail-duplicated into 76; outer_loop_latch, and into shared_preheader, and then removed. This leaves 77; shared_loop_header as the header of both loops. The end result 78; is that there are 2 valid loops, and that they share a header. If we re-ran 79; the loop analysis, it would classify this as a single loop. 80; So far this is fine as far as layout is concerned. 81; After layout we tail merge blocks merge_other and merge_predecessor_split. 82; We do this even though they share only a single instruction, because 83; merge_predecessor_split falls through to their shared successor: 84; outer_loop_latch. 85; The rest of the blocks in the function are noise unfortunately. Bugpoint 86; couldn't shrink the test any further. 87 88define 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 { 89; CHECK-LABEL: loop_shared_header: 90; CHECK: # %bb.0: # %entry 91; CHECK-NEXT: pushq %rbp 92; CHECK-NEXT: pushq %r15 93; CHECK-NEXT: pushq %r14 94; CHECK-NEXT: pushq %r13 95; CHECK-NEXT: pushq %r12 96; CHECK-NEXT: pushq %rbx 97; CHECK-NEXT: pushq %rax 98; CHECK-NEXT: movl $1, %ebx 99; CHECK-NEXT: xorl %eax, %eax 100; CHECK-NEXT: testb %al, %al 101; CHECK-NEXT: jne .LBB1_24 102; CHECK-NEXT: # %bb.1: # %if.end19 103; CHECK-NEXT: movl %esi, %ebp 104; CHECK-NEXT: movq %rdi, %r15 105; CHECK-NEXT: movl (%rax), %r13d 106; CHECK-NEXT: leal (,%r13,4), %ebx 107; CHECK-NEXT: movl %ebx, %r12d 108; CHECK-NEXT: movl $1, %esi 109; CHECK-NEXT: movq %r12, %rdi 110; CHECK-NEXT: callq cli_calloc@PLT 111; CHECK-NEXT: testl %ebp, %ebp 112; CHECK-NEXT: je .LBB1_23 113; CHECK-NEXT: # %bb.2: # %if.end19 114; CHECK-NEXT: testl %r13d, %r13d 115; CHECK-NEXT: je .LBB1_23 116; CHECK-NEXT: # %bb.3: # %if.end19 117; CHECK-NEXT: movq %rax, %r14 118; CHECK-NEXT: xorl %eax, %eax 119; CHECK-NEXT: testb %al, %al 120; CHECK-NEXT: jne .LBB1_23 121; CHECK-NEXT: # %bb.4: # %if.end19 122; CHECK-NEXT: cmpq %r15, %r14 123; CHECK-NEXT: jb .LBB1_23 124; CHECK-NEXT: # %bb.5: # %if.end50 125; CHECK-NEXT: movq %r14, %rdi 126; CHECK-NEXT: movq %r12, %rdx 127; CHECK-NEXT: callq memcpy@PLT 128; CHECK-NEXT: cmpl $4, %ebx 129; CHECK-NEXT: jb .LBB1_26 130; CHECK-NEXT: # %bb.6: # %shared_preheader 131; CHECK-NEXT: movb $32, %cl 132; CHECK-NEXT: xorl %eax, %eax 133; CHECK-NEXT: jmp .LBB1_8 134; CHECK-NEXT: .p2align 4, 0x90 135; CHECK-NEXT: .LBB1_7: # %merge_predecessor_split 136; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 137; CHECK-NEXT: movb $32, %cl 138; CHECK-NEXT: .LBB1_8: # %outer_loop_header 139; CHECK-NEXT: # =>This Loop Header: Depth=1 140; CHECK-NEXT: # Child Loop BB1_9 Depth 2 141; CHECK-NEXT: testl %r13d, %r13d 142; CHECK-NEXT: je .LBB1_16 143; CHECK-NEXT: .p2align 4, 0x90 144; CHECK-NEXT: .LBB1_9: # %shared_loop_header 145; CHECK-NEXT: # Parent Loop BB1_8 Depth=1 146; CHECK-NEXT: # => This Inner Loop Header: Depth=2 147; CHECK-NEXT: testq %r14, %r14 148; CHECK-NEXT: jne .LBB1_25 149; CHECK-NEXT: # %bb.10: # %inner_loop_body 150; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=2 151; CHECK-NEXT: testl %eax, %eax 152; CHECK-NEXT: jns .LBB1_9 153; CHECK-NEXT: # %bb.11: # %if.end96.i 154; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 155; CHECK-NEXT: cmpl $3, %r13d 156; CHECK-NEXT: jae .LBB1_20 157; CHECK-NEXT: # %bb.12: # %if.end287.i 158; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 159; CHECK-NEXT: testb %al, %al 160; CHECK-NEXT: # implicit-def: $cl 161; CHECK-NEXT: jne .LBB1_8 162; CHECK-NEXT: # %bb.13: # %if.end308.i 163; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 164; CHECK-NEXT: testb %al, %al 165; CHECK-NEXT: je .LBB1_7 166; CHECK-NEXT: # %bb.14: # %if.end335.i 167; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 168; CHECK-NEXT: xorl %ecx, %ecx 169; CHECK-NEXT: testb %cl, %cl 170; CHECK-NEXT: jne .LBB1_8 171; CHECK-NEXT: # %bb.15: # %merge_other 172; CHECK-NEXT: # in Loop: Header=BB1_8 Depth=1 173; CHECK-NEXT: # implicit-def: $cl 174; CHECK-NEXT: jmp .LBB1_8 175; CHECK-NEXT: .LBB1_23: 176; CHECK-NEXT: movl $1, %ebx 177; CHECK-NEXT: jmp .LBB1_24 178; CHECK-NEXT: .LBB1_16: # %while.cond.us1412.i 179; CHECK-NEXT: xorl %eax, %eax 180; CHECK-NEXT: testb %al, %al 181; CHECK-NEXT: movl $1, %ebx 182; CHECK-NEXT: jne .LBB1_18 183; CHECK-NEXT: # %bb.17: # %while.cond.us1412.i 184; CHECK-NEXT: decb %cl 185; CHECK-NEXT: jne .LBB1_24 186; CHECK-NEXT: .LBB1_18: # %if.end41.us1436.i 187; CHECK-NEXT: .LBB1_20: # %if.then99.i 188; CHECK-NEXT: movq .str.6@GOTPCREL(%rip), %rdi 189; CHECK-NEXT: xorl %ebx, %ebx 190; CHECK-NEXT: xorl %eax, %eax 191; CHECK-NEXT: callq cli_dbgmsg@PLT 192; CHECK-NEXT: .LBB1_24: # %cleanup 193; CHECK-NEXT: movl %ebx, %eax 194; CHECK-NEXT: addq $8, %rsp 195; CHECK-NEXT: popq %rbx 196; CHECK-NEXT: popq %r12 197; CHECK-NEXT: popq %r13 198; CHECK-NEXT: popq %r14 199; CHECK-NEXT: popq %r15 200; CHECK-NEXT: popq %rbp 201; CHECK-NEXT: retq 202; CHECK-NEXT: .LBB1_25: # %wunpsect.exit.thread.loopexit389 203; CHECK-NEXT: .LBB1_26: # %wunpsect.exit.thread.loopexit391 204entry: 205 %0 = load i32, i32* undef, align 4 206 %mul = shl nsw i32 %0, 2 207 br i1 undef, label %if.end19, label %cleanup 208 209if.end19: ; preds = %entry 210 %conv = zext i32 %mul to i64 211 %call = tail call i8* @cli_calloc(i64 %conv, i64 1) 212 %1 = icmp eq i32 %exesz, 0 213 %notrhs = icmp eq i32 %0, 0 214 %or.cond117.not = or i1 %1, %notrhs 215 %or.cond202 = or i1 %or.cond117.not, undef 216 %cmp35 = icmp ult i8* %call, %exe 217 %or.cond203 = or i1 %or.cond202, %cmp35 218 br i1 %or.cond203, label %cleanup, label %if.end50 219 220if.end50: ; preds = %if.end19 221 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i1 false) 222 %cmp1.i.i = icmp ugt i32 %mul, 3 223 br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391 224 225shared_preheader: ; preds = %if.end50 226 br label %outer_loop_header 227 228outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader 229 %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ] 230 %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ] 231 %2 = icmp eq i32 %0, 0 232 br i1 %2, label %while.cond.us1412.i, label %shared_loop_header 233 234while.cond.us1412.i: ; preds = %outer_loop_header 235 %.pre.i = add i8 %bits.1.i, -1 236 %tobool2.us1420.i = icmp eq i8 %.pre.i, 0 237 %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i 238 br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup 239 240if.end41.us1436.i: ; preds = %while.cond.us1412.i 241 unreachable 242 243shared_loop_header: ; preds = %dup_early2, %dup_early1 244 %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ] 245 %cmp3.i1172.i = icmp ult i8* null, %call 246 br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body 247 248inner_loop_body: ; preds = %shared_loop_header 249 %3 = icmp slt i32 undef, 0 250 br i1 %3, label %if.end96.i, label %shared_loop_header 251 252dead_block: ; preds = %inner_loop_body 253 %cmp75.i = icmp ult i8* %dst.0.i, null 254 br label %shared_loop_header 255 256if.end96.i: ; preds = %inner_loop_body 257 %cmp97.i = icmp ugt i32 %0, 2 258 br i1 %cmp97.i, label %if.then99.i, label %if.end287.i 259 260if.then99.i: ; preds = %if.end96.i 261 tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef) 262 br label %cleanup 263 264if.end287.i: ; preds = %if.end96.i 265 %cmp291.i = icmp ne i32 %0, 1 266 %conv294.i = select i1 %cmp291.i, i16 4, i16 3 267 br i1 undef, label %if.end308.i, label %outer_loop_latch 268 269if.end308.i: ; preds = %if.end287.i 270 br i1 undef, label %if.end335.i, label %merge_predecessor_split 271 272merge_predecessor_split: ; preds = %if.end308.i 273 %4 = bitcast i8* undef to i32* 274 br label %outer_loop_latch 275 276if.end335.i: ; preds = %if.end308.i 277 br i1 undef, label %outer_loop_latch, label %merge_other 278 279merge_other: ; preds = %if.end335.i 280 br label %outer_loop_latch 281 282outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i 283 %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ] 284 %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ] 285 %5 = add i16 %backsize.0.i, -1 286 %6 = zext i16 %5 to i64 287 %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1 288 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6 289 br label %outer_loop_header 290 291wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header 292 unreachable 293 294wunpsect.exit.thread.loopexit391: ; preds = %if.end50 295 unreachable 296 297cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry 298 %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ] 299 ret i32 %retval.0 300} 301 302; Function Attrs: nounwind 303declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0 304 305; Function Attrs: nounwind 306declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0 307 308; Function Attrs: argmemonly nounwind 309declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1 310attributes #0 = { nounwind } 311attributes #1 = { argmemonly nounwind } 312