1 ; RUN: opt -passes=loop-simplify -S < %s | FileCheck %s
3 ; This will test whether or not the metadata from the current loop 1 latch
4 ; is removed, and applied to the new latch after running the loop-simplify
5 ; pass on this function. The loop simplify pass ensures that each loop has exit
6 ; blocks which only have predecessors that are inside of the loop. This
7 ; guarantees that the loop preheader/header will dominate the exit blocks. For
8 ; this function currently loop 2 does not have a dedicated exit block.
10 ; CHECK: loop_1_loopHeader.loopexit:
11 ; CHECK: br label %loop_1_loopHeader, !llvm.loop [[LOOP_1_LATCH_MD:![0-9]+]]
12 ; CHECK: loop_2_loopHeader
13 ; CHECK: br i1 %grt_B, label %loop_1_loopHeader.loopexit, label %loop_2_do
14 ; CHECK-NOT: br i1 %grt_B, label %loop_1_loopHeader, label %loop_2_do, !llvm.loop{{.*}}
16 define void @function(i32 %A) {
20 br label %loop_1_loopHeader
22 loop_1_loopHeader: ; preds = %loop_2_loopHeader, %entry
23 %loop_1_idx = phi i32 [ 1, %entry], [ %loop_1_update_idx, %loop_2_loopHeader ]
24 %grt_C = icmp slt i32 %loop_1_idx, %C
25 br i1 %grt_C, label %exit, label %loop_1_do
27 loop_1_do: ; preds = %loop_1_loopHeader
28 %loop_1_update_idx = add nuw nsw i32 %loop_1_idx, 1
29 br label %loop_2_loopHeader
31 loop_2_loopHeader: ; preds = %loop_2_do, %_loop_1_do
32 %loop_2_idx = phi i32 [ 1, %loop_1_do ], [ %loop_2_update_idx, %loop_2_do ]
33 %grt_B = icmp slt i32 %loop_2_idx, %B
34 br i1 %grt_B, label %loop_1_loopHeader, label %loop_2_do, !llvm.loop !0
36 loop_2_do: ; preds = %loop_2_loopHeader
37 %loop_2_update_idx = add nuw nsw i32 %loop_2_idx, 1
38 br label %loop_2_loopHeader, !llvm.loop !2
40 exit: ; preds = %loop_1_loopHeader
44 !0 = distinct !{!0, !1}
45 !1 = !{!"llvm.loop.unroll.disable"}
46 !2 = distinct !{!2, !1}