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_27 102; CHECK-NEXT: # %bb.1: # %if.end19 103; CHECK-NEXT: movl %esi, %r13d 104; CHECK-NEXT: movq %rdi, %r12 105; CHECK-NEXT: movl (%rax), %ebp 106; CHECK-NEXT: leal (,%rbp,4), %r14d 107; CHECK-NEXT: movl %r14d, %r15d 108; CHECK-NEXT: movl $1, %esi 109; CHECK-NEXT: movq %r15, %rdi 110; CHECK-NEXT: callq cli_calloc@PLT 111; CHECK-NEXT: testl %r13d, %r13d 112; CHECK-NEXT: je .LBB1_26 113; CHECK-NEXT: # %bb.2: # %if.end19 114; CHECK-NEXT: testl %ebp, %ebp 115; CHECK-NEXT: je .LBB1_26 116; CHECK-NEXT: # %bb.3: # %if.end19 117; CHECK-NEXT: movq %rax, %rbx 118; CHECK-NEXT: xorl %eax, %eax 119; CHECK-NEXT: testb %al, %al 120; CHECK-NEXT: jne .LBB1_26 121; CHECK-NEXT: # %bb.4: # %if.end19 122; CHECK-NEXT: cmpq %r12, %rbx 123; CHECK-NEXT: jb .LBB1_26 124; CHECK-NEXT: # %bb.5: # %if.end50 125; CHECK-NEXT: movq %rbx, %rdi 126; CHECK-NEXT: movq %r15, %rdx 127; CHECK-NEXT: callq memcpy@PLT 128; CHECK-NEXT: cmpl $4, %r14d 129; CHECK-NEXT: jb .LBB1_29 130; CHECK-NEXT: # %bb.6: # %shared_preheader 131; CHECK-NEXT: movb $32, %dl 132; CHECK-NEXT: xorl %eax, %eax 133; CHECK-NEXT: # implicit-def: $rcx 134; CHECK-NEXT: jmp .LBB1_9 135; CHECK-NEXT: .p2align 4, 0x90 136; CHECK-NEXT: .LBB1_7: # %merge_predecessor_split 137; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 138; CHECK-NEXT: movb $32, %dl 139; CHECK-NEXT: xorl %esi, %esi 140; CHECK-NEXT: .LBB1_8: # %outer_loop_latch 141; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 142; CHECK-NEXT: movzwl %si, %esi 143; CHECK-NEXT: decl %esi 144; CHECK-NEXT: movzwl %si, %esi 145; CHECK-NEXT: leaq 1(%rcx,%rsi), %rcx 146; CHECK-NEXT: .LBB1_9: # %outer_loop_header 147; CHECK-NEXT: # =>This Loop Header: Depth=1 148; CHECK-NEXT: # Child Loop BB1_10 Depth 2 149; CHECK-NEXT: testl %ebp, %ebp 150; CHECK-NEXT: je .LBB1_19 151; CHECK-NEXT: .p2align 4, 0x90 152; CHECK-NEXT: .LBB1_10: # %shared_loop_header 153; CHECK-NEXT: # Parent Loop BB1_9 Depth=1 154; CHECK-NEXT: # => This Inner Loop Header: Depth=2 155; CHECK-NEXT: testq %rbx, %rbx 156; CHECK-NEXT: jne .LBB1_28 157; CHECK-NEXT: # %bb.11: # %inner_loop_body 158; CHECK-NEXT: # in Loop: Header=BB1_10 Depth=2 159; CHECK-NEXT: testl %eax, %eax 160; CHECK-NEXT: jns .LBB1_10 161; CHECK-NEXT: # %bb.12: # %if.end96.i 162; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 163; CHECK-NEXT: cmpl $3, %ebp 164; CHECK-NEXT: jae .LBB1_23 165; CHECK-NEXT: # %bb.13: # %if.end287.i 166; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 167; CHECK-NEXT: xorl %esi, %esi 168; CHECK-NEXT: cmpl $1, %ebp 169; CHECK-NEXT: setne %dl 170; CHECK-NEXT: testb %al, %al 171; CHECK-NEXT: jne .LBB1_17 172; CHECK-NEXT: # %bb.14: # %if.end308.i 173; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 174; CHECK-NEXT: testb %al, %al 175; CHECK-NEXT: je .LBB1_7 176; CHECK-NEXT: # %bb.15: # %if.end335.i 177; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 178; CHECK-NEXT: xorl %edx, %edx 179; CHECK-NEXT: testb %dl, %dl 180; CHECK-NEXT: movl $0, %esi 181; CHECK-NEXT: jne .LBB1_8 182; CHECK-NEXT: # %bb.16: # %merge_other 183; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 184; CHECK-NEXT: xorl %esi, %esi 185; CHECK-NEXT: jmp .LBB1_18 186; CHECK-NEXT: .p2align 4, 0x90 187; CHECK-NEXT: .LBB1_17: # in Loop: Header=BB1_9 Depth=1 188; CHECK-NEXT: movb %dl, %sil 189; CHECK-NEXT: addl $3, %esi 190; CHECK-NEXT: .LBB1_18: # %outer_loop_latch 191; CHECK-NEXT: # in Loop: Header=BB1_9 Depth=1 192; CHECK-NEXT: # implicit-def: $dl 193; CHECK-NEXT: jmp .LBB1_8 194; CHECK-NEXT: .LBB1_26: 195; CHECK-NEXT: movl $1, %ebx 196; CHECK-NEXT: jmp .LBB1_27 197; CHECK-NEXT: .LBB1_19: # %while.cond.us1412.i 198; CHECK-NEXT: xorl %eax, %eax 199; CHECK-NEXT: testb %al, %al 200; CHECK-NEXT: movl $1, %ebx 201; CHECK-NEXT: jne .LBB1_21 202; CHECK-NEXT: # %bb.20: # %while.cond.us1412.i 203; CHECK-NEXT: decb %dl 204; CHECK-NEXT: jne .LBB1_27 205; CHECK-NEXT: .LBB1_21: # %if.end41.us1436.i 206; CHECK-NEXT: .LBB1_23: # %if.then99.i 207; CHECK-NEXT: movq .str.6@GOTPCREL(%rip), %rdi 208; CHECK-NEXT: xorl %ebx, %ebx 209; CHECK-NEXT: xorl %eax, %eax 210; CHECK-NEXT: callq cli_dbgmsg@PLT 211; CHECK-NEXT: .LBB1_27: # %cleanup 212; CHECK-NEXT: movl %ebx, %eax 213; CHECK-NEXT: addq $8, %rsp 214; CHECK-NEXT: popq %rbx 215; CHECK-NEXT: popq %r12 216; CHECK-NEXT: popq %r13 217; CHECK-NEXT: popq %r14 218; CHECK-NEXT: popq %r15 219; CHECK-NEXT: popq %rbp 220; CHECK-NEXT: retq 221; CHECK-NEXT: .LBB1_28: # %wunpsect.exit.thread.loopexit389 222; CHECK-NEXT: .LBB1_29: # %wunpsect.exit.thread.loopexit391 223entry: 224 %0 = load i32, i32* undef, align 4 225 %mul = shl nsw i32 %0, 2 226 br i1 undef, label %if.end19, label %cleanup 227 228if.end19: ; preds = %entry 229 %conv = zext i32 %mul to i64 230 %call = tail call i8* @cli_calloc(i64 %conv, i64 1) 231 %1 = icmp eq i32 %exesz, 0 232 %notrhs = icmp eq i32 %0, 0 233 %or.cond117.not = or i1 %1, %notrhs 234 %or.cond202 = or i1 %or.cond117.not, undef 235 %cmp35 = icmp ult i8* %call, %exe 236 %or.cond203 = or i1 %or.cond202, %cmp35 237 br i1 %or.cond203, label %cleanup, label %if.end50 238 239if.end50: ; preds = %if.end19 240 tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %call, i8* undef, i64 %conv, i1 false) 241 %cmp1.i.i = icmp ugt i32 %mul, 3 242 br i1 %cmp1.i.i, label %shared_preheader, label %wunpsect.exit.thread.loopexit391 243 244shared_preheader: ; preds = %if.end50 245 br label %outer_loop_header 246 247outer_loop_header: ; preds = %outer_loop_latch, %shared_preheader 248 %bits.1.i = phi i8 [ 32, %shared_preheader ], [ %bits.43.i, %outer_loop_latch ] 249 %dst.0.ph.i = phi i8* [ undef, %shared_preheader ], [ %scevgep679.i, %outer_loop_latch ] 250 %2 = icmp eq i32 %0, 0 251 br i1 %2, label %while.cond.us1412.i, label %shared_loop_header 252 253while.cond.us1412.i: ; preds = %outer_loop_header 254 %.pre.i = add i8 %bits.1.i, -1 255 %tobool2.us1420.i = icmp eq i8 %.pre.i, 0 256 %or.cond.us1421.i = or i1 undef, %tobool2.us1420.i 257 br i1 %or.cond.us1421.i, label %if.end41.us1436.i, label %cleanup 258 259if.end41.us1436.i: ; preds = %while.cond.us1412.i 260 unreachable 261 262shared_loop_header: ; preds = %dup_early2, %dup_early1 263 %dst.0.i = phi i8* [ undef, %inner_loop_body ], [ %dst.0.ph.i, %outer_loop_header ], [ undef, %dead_block ] 264 %cmp3.i1172.i = icmp ult i8* null, %call 265 br i1 %cmp3.i1172.i, label %wunpsect.exit.thread.loopexit389, label %inner_loop_body 266 267inner_loop_body: ; preds = %shared_loop_header 268 %3 = icmp slt i32 undef, 0 269 br i1 %3, label %if.end96.i, label %shared_loop_header 270 271dead_block: ; preds = %inner_loop_body 272 %cmp75.i = icmp ult i8* %dst.0.i, null 273 br label %shared_loop_header 274 275if.end96.i: ; preds = %inner_loop_body 276 %cmp97.i = icmp ugt i32 %0, 2 277 br i1 %cmp97.i, label %if.then99.i, label %if.end287.i 278 279if.then99.i: ; preds = %if.end96.i 280 tail call void (i8*, ...) @cli_dbgmsg(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 undef) 281 br label %cleanup 282 283if.end287.i: ; preds = %if.end96.i 284 %cmp291.i = icmp ne i32 %0, 1 285 %conv294.i = select i1 %cmp291.i, i16 4, i16 3 286 br i1 undef, label %if.end308.i, label %outer_loop_latch 287 288if.end308.i: ; preds = %if.end287.i 289 br i1 undef, label %if.end335.i, label %merge_predecessor_split 290 291merge_predecessor_split: ; preds = %if.end308.i 292 %4 = bitcast i8* undef to i32* 293 br label %outer_loop_latch 294 295if.end335.i: ; preds = %if.end308.i 296 br i1 undef, label %outer_loop_latch, label %merge_other 297 298merge_other: ; preds = %if.end335.i 299 br label %outer_loop_latch 300 301outer_loop_latch: ; preds = %merge_other, %if.end335.i, %merge_predecessor_split, %if.end287.i 302 %bits.43.i = phi i8 [ undef, %if.end287.i ], [ undef, %merge_other ], [ 32, %merge_predecessor_split ], [ 0, %if.end335.i ] 303 %backsize.0.i = phi i16 [ %conv294.i, %if.end287.i ], [ 0, %merge_other ], [ 0, %merge_predecessor_split ], [ 0, %if.end335.i ] 304 %5 = add i16 %backsize.0.i, -1 305 %6 = zext i16 %5 to i64 306 %scevgep.i = getelementptr i8, i8* %dst.0.ph.i, i64 1 307 %scevgep679.i = getelementptr i8, i8* %scevgep.i, i64 %6 308 br label %outer_loop_header 309 310wunpsect.exit.thread.loopexit389: ; preds = %shared_loop_header 311 unreachable 312 313wunpsect.exit.thread.loopexit391: ; preds = %if.end50 314 unreachable 315 316cleanup: ; preds = %if.then99.i, %while.cond.us1412.i, %if.end19, %entry 317 %retval.0 = phi i32 [ 0, %if.then99.i ], [ 1, %entry ], [ 1, %if.end19 ], [ 1, %while.cond.us1412.i ] 318 ret i32 %retval.0 319} 320 321; Function Attrs: nounwind 322declare void @cli_dbgmsg(i8*, ...) local_unnamed_addr #0 323 324; Function Attrs: nounwind 325declare i8* @cli_calloc(i64, i64) local_unnamed_addr #0 326 327; Function Attrs: argmemonly nounwind 328declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) #1 329attributes #0 = { nounwind } 330attributes #1 = { argmemonly nounwind } 331