1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -verify-loop-info -passes=irce -S < %s | FileCheck %s
3 ; RUN: opt -verify-loop-info -passes='require<branch-prob>,irce' -S < %s | FileCheck %s
5 define void @multiple_access_no_preloop(
6 ; CHECK-LABEL: @multiple_access_no_preloop(
8 ; CHECK-NEXT: [[LEN_A:%.*]] = load i32, ptr [[A_LEN_PTR:%.*]], align 4, !range [[RNG0:![0-9]+]]
9 ; CHECK-NEXT: [[LEN_B:%.*]] = load i32, ptr [[B_LEN_PTR:%.*]], align 4, !range [[RNG0]]
10 ; CHECK-NEXT: [[FIRST_ITR_CHECK:%.*]] = icmp sgt i32 [[N:%.*]], 0
11 ; CHECK-NEXT: br i1 [[FIRST_ITR_CHECK]], label [[LOOP_PREHEADER:%.*]], label [[EXIT:%.*]]
12 ; CHECK: loop.preheader:
13 ; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[LEN_B]], i32 [[LEN_A]])
14 ; CHECK-NEXT: [[SMIN1:%.*]] = call i32 @llvm.smin.i32(i32 [[SMIN]], i32 [[N]])
15 ; CHECK-NEXT: [[EXIT_MAINLOOP_AT:%.*]] = call i32 @llvm.smax.i32(i32 [[SMIN1]], i32 0)
16 ; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 0, [[EXIT_MAINLOOP_AT]]
17 ; CHECK-NEXT: br i1 [[TMP0]], label [[LOOP_PREHEADER2:%.*]], label [[MAIN_PSEUDO_EXIT:%.*]]
18 ; CHECK: loop.preheader2:
19 ; CHECK-NEXT: br label [[LOOP:%.*]]
21 ; CHECK-NEXT: [[IDX:%.*]] = phi i32 [ [[IDX_NEXT:%.*]], [[IN_BOUNDS_B:%.*]] ], [ 0, [[LOOP_PREHEADER2]] ]
22 ; CHECK-NEXT: [[IDX_NEXT]] = add nsw i32 [[IDX]], 1
23 ; CHECK-NEXT: [[ABC_A:%.*]] = icmp slt i32 [[IDX]], [[LEN_A]]
24 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS_A:%.*]], label [[OUT_OF_BOUNDS_LOOPEXIT3:%.*]], !prof [[PROF1:![0-9]+]]
26 ; CHECK-NEXT: [[ADDR_A:%.*]] = getelementptr i32, ptr [[ARR_A:%.*]], i32 [[IDX]]
27 ; CHECK-NEXT: store i32 0, ptr [[ADDR_A]], align 4
28 ; CHECK-NEXT: [[ABC_B:%.*]] = icmp slt i32 [[IDX]], [[LEN_B]]
29 ; CHECK-NEXT: br i1 true, label [[IN_BOUNDS_B]], label [[OUT_OF_BOUNDS_LOOPEXIT3]], !prof [[PROF1]]
31 ; CHECK-NEXT: [[ADDR_B:%.*]] = getelementptr i32, ptr [[ARR_B:%.*]], i32 [[IDX]]
32 ; CHECK-NEXT: store i32 -1, ptr [[ADDR_B]], align 4
33 ; CHECK-NEXT: [[NEXT:%.*]] = icmp slt i32 [[IDX_NEXT]], [[N]]
34 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[IDX_NEXT]], [[EXIT_MAINLOOP_AT]]
35 ; CHECK-NEXT: br i1 [[TMP1]], label [[LOOP]], label [[MAIN_EXIT_SELECTOR:%.*]]
36 ; CHECK: main.exit.selector:
37 ; CHECK-NEXT: [[IDX_NEXT_LCSSA:%.*]] = phi i32 [ [[IDX_NEXT]], [[IN_BOUNDS_B]] ]
38 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[IDX_NEXT_LCSSA]], [[N]]
39 ; CHECK-NEXT: br i1 [[TMP2]], label [[MAIN_PSEUDO_EXIT]], label [[EXIT_LOOPEXIT:%.*]]
40 ; CHECK: main.pseudo.exit:
41 ; CHECK-NEXT: [[IDX_COPY:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
42 ; CHECK-NEXT: [[INDVAR_END:%.*]] = phi i32 [ 0, [[LOOP_PREHEADER]] ], [ [[IDX_NEXT_LCSSA]], [[MAIN_EXIT_SELECTOR]] ]
43 ; CHECK-NEXT: br label [[POSTLOOP:%.*]]
44 ; CHECK: out.of.bounds.loopexit:
45 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS:%.*]]
46 ; CHECK: out.of.bounds.loopexit3:
47 ; CHECK-NEXT: br label [[OUT_OF_BOUNDS]]
48 ; CHECK: out.of.bounds:
49 ; CHECK-NEXT: ret void
50 ; CHECK: exit.loopexit.loopexit:
51 ; CHECK-NEXT: br label [[EXIT_LOOPEXIT]]
52 ; CHECK: exit.loopexit:
53 ; CHECK-NEXT: br label [[EXIT]]
55 ; CHECK-NEXT: ret void
57 ; CHECK-NEXT: br label [[LOOP_POSTLOOP:%.*]]
58 ; CHECK: loop.postloop:
59 ; CHECK-NEXT: [[IDX_POSTLOOP:%.*]] = phi i32 [ [[IDX_NEXT_POSTLOOP:%.*]], [[IN_BOUNDS_B_POSTLOOP:%.*]] ], [ [[IDX_COPY]], [[POSTLOOP]] ]
60 ; CHECK-NEXT: [[IDX_NEXT_POSTLOOP]] = add i32 [[IDX_POSTLOOP]], 1
61 ; CHECK-NEXT: [[ABC_A_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[LEN_A]]
62 ; CHECK-NEXT: br i1 [[ABC_A_POSTLOOP]], label [[IN_BOUNDS_A_POSTLOOP:%.*]], label [[OUT_OF_BOUNDS_LOOPEXIT:%.*]], !prof [[PROF1]]
63 ; CHECK: in.bounds.a.postloop:
64 ; CHECK-NEXT: [[ADDR_A_POSTLOOP:%.*]] = getelementptr i32, ptr [[ARR_A]], i32 [[IDX_POSTLOOP]]
65 ; CHECK-NEXT: store i32 0, ptr [[ADDR_A_POSTLOOP]], align 4
66 ; CHECK-NEXT: [[ABC_B_POSTLOOP:%.*]] = icmp slt i32 [[IDX_POSTLOOP]], [[LEN_B]]
67 ; CHECK-NEXT: br i1 [[ABC_B_POSTLOOP]], label [[IN_BOUNDS_B_POSTLOOP]], label [[OUT_OF_BOUNDS_LOOPEXIT]], !prof [[PROF1]]
68 ; CHECK: in.bounds.b.postloop:
69 ; CHECK-NEXT: [[ADDR_B_POSTLOOP:%.*]] = getelementptr i32, ptr [[ARR_B]], i32 [[IDX_POSTLOOP]]
70 ; CHECK-NEXT: store i32 -1, ptr [[ADDR_B_POSTLOOP]], align 4
71 ; CHECK-NEXT: [[NEXT_POSTLOOP:%.*]] = icmp slt i32 [[IDX_NEXT_POSTLOOP]], [[N]]
72 ; CHECK-NEXT: br i1 [[NEXT_POSTLOOP]], label [[LOOP_POSTLOOP]], label [[EXIT_LOOPEXIT_LOOPEXIT:%.*]], !llvm.loop [[LOOP2:![0-9]+]], !loop_constrainer.loop.clone [[META7:![0-9]+]]
74 ptr %arr_a, ptr %a_len_ptr, ptr %arr_b, ptr %b_len_ptr, i32 %n) {
77 %len.a = load i32, ptr %a_len_ptr, !range !0
78 %len.b = load i32, ptr %b_len_ptr, !range !0
79 %first.itr.check = icmp sgt i32 %n, 0
80 br i1 %first.itr.check, label %loop, label %exit
83 %idx = phi i32 [ 0, %entry ] , [ %idx.next, %in.bounds.b ]
84 %idx.next = add i32 %idx, 1
85 %abc.a = icmp slt i32 %idx, %len.a
86 br i1 %abc.a, label %in.bounds.a, label %out.of.bounds, !prof !1
89 %addr.a = getelementptr i32, ptr %arr_a, i32 %idx
90 store i32 0, ptr %addr.a
91 %abc.b = icmp slt i32 %idx, %len.b
92 br i1 %abc.b, label %in.bounds.b, label %out.of.bounds, !prof !1
95 %addr.b = getelementptr i32, ptr %arr_b, i32 %idx
96 store i32 -1, ptr %addr.b
97 %next = icmp slt i32 %idx.next, %n
98 br i1 %next, label %loop, label %exit
107 !0 = !{i32 0, i32 2147483647}
108 !1 = !{!"branch_weights", i32 128, i32 4}