1 ; RUN: opt -irce -S < %s 2>&1 | FileCheck %s
2 ; RUN: opt -passes='require<branch-prob>,loop(irce)' -S < %s 2>&1 | FileCheck %s
4 ; test that the pre and post loops have loop metadata which disables any further
7 ; generates a post loop, which should have metadata !llvm.loop !2
8 ; Function Attrs: alwaysinline
9 define void @inner_loop(i32* %arr, i32* %a_len_ptr, i32 %n) #0 {
10 ; CHECK-LABEL: inner_loop(
11 ; CHECK-LABEL: in.bounds.postloop
12 ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit.loopexit, !llvm.loop !2, !irce.loop.clone !7
15 %len = load i32, i32* %a_len_ptr, !range !0
16 %first.itr.check = icmp sgt i32 %n, 0
17 br i1 %first.itr.check, label %loop, label %exit
19 loop: ; preds = %in.bounds, %entry
20 %idx = phi i32 [ 0, %entry ], [ %idx.next, %in.bounds ]
21 %idx.next = add i32 %idx, 1
22 %abc = icmp slt i32 %idx, %len
23 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
25 in.bounds: ; preds = %loop
26 %addr = getelementptr i32, i32* %arr, i32 %idx
27 store i32 0, i32* %addr
28 %next = icmp slt i32 %idx.next, %n
29 br i1 %next, label %loop, label %exit
31 out.of.bounds: ; preds = %loop
34 exit: ; preds = %in.bounds, %entry
38 ; add loop metadata for pre and post loops
39 define void @single_access_with_preloop(i32 *%arr, i32 *%a_len_ptr, i32 %n, i32 %offset) {
40 ; CHECK-LABEL: @single_access_with_preloop(
41 ; CHECK-LABEL: in.bounds.preloop
42 ; CHECK: br i1 [[COND:%[^ ]+]], label %loop.preloop, label %preloop.exit.selector, !llvm.loop !8, !irce.loop.clone !7
43 ; CHECK-LABEL: in.bounds.postloop
44 ; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit.loopexit, !llvm.loop !9, !irce.loop.clone !7
46 %len = load i32, i32* %a_len_ptr, !range !0
47 %first.itr.check = icmp sgt i32 %n, 0
48 br i1 %first.itr.check, label %loop, label %exit
51 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds ]
52 %idx.next = add i32 %idx, 1
53 %array.idx = add i32 %idx, %offset
54 %abc.high = icmp slt i32 %array.idx, %len
55 %abc.low = icmp sge i32 %array.idx, 0
56 %abc = and i1 %abc.low, %abc.high
57 br i1 %abc, label %in.bounds, label %out.of.bounds, !prof !1
60 %addr = getelementptr i32, i32* %arr, i32 %array.idx
61 store i32 0, i32* %addr
62 %next = icmp slt i32 %idx.next, %n
63 br i1 %next, label %loop, label %exit
71 attributes #0 = { alwaysinline }
73 !0 = !{i32 0, i32 2147483647}
74 !1 = !{!"branch_weights", i32 64, i32 4}
75 !2 = distinct !{!2, !3, !4, !5, !6}
76 !3 = !{!"llvm.loop.unroll.disable"}
77 !4 = !{!"llvm.loop.vectorize.enable", i1 false}
78 !5 = !{!"llvm.loop.licm_versioning.disable"}
79 !6 = !{!"llvm.loop.distribute.enable", i1 false}
81 !8 = distinct !{!8, !3, !4, !5}
82 !9 = distinct !{!9, !3, !4, !5}