1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -loop-unroll -unroll-threshold=42 | FileCheck %s --check-prefix=ANALYZE-FULL
4 ; This test is supposed to check that calls to @llvm.assume builtin are not
5 ; prohibiting the analysis of full unroll profitability in case the cost of the
6 ; unrolled loop (not acounting to any simplifications done by such unrolling) is
7 ; higher than some threshold.
9 ; Ensure that we indeed are testing this code path by verifying that the loop is
10 ; not unrolled without such analysis:
12 ; RUN: opt -S < %s -loop-unroll -unroll-threshold=42 -unroll-max-iteration-count-to-analyze=2 \
13 ; RUN: -unroll-peel-max-count=0 | FileCheck %s --check-prefix=DONT-ANALYZE-FULL
15 ; Function Attrs: nounwind
16 declare void @llvm.assume(i1) #1
18 define i32 @foo(i32* %a) {
19 ; ANALYZE-FULL-LABEL: @foo(
20 ; ANALYZE-FULL-NEXT: entry:
21 ; ANALYZE-FULL-NEXT: br label [[FOR_BODY:%.*]]
22 ; ANALYZE-FULL: for.body:
23 ; ANALYZE-FULL-NEXT: br i1 true, label [[DO_STORE:%.*]], label [[FOR_NEXT:%.*]]
24 ; ANALYZE-FULL: do_store:
25 ; ANALYZE-FULL-NEXT: store i32 0, i32* [[A:%.*]]
26 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT]]
27 ; ANALYZE-FULL: for.next:
28 ; ANALYZE-FULL-NEXT: br i1 true, label [[DO_STORE_1:%.*]], label [[FOR_NEXT_1:%.*]]
29 ; ANALYZE-FULL: do_store.1:
30 ; ANALYZE-FULL-NEXT: [[GEP_1:%.*]] = getelementptr i32, i32* [[A]], i32 1
31 ; ANALYZE-FULL-NEXT: store i32 1, i32* [[GEP_1]]
32 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_1]]
33 ; ANALYZE-FULL: for.next.1:
34 ; ANALYZE-FULL-NEXT: br i1 true, label [[DO_STORE_2:%.*]], label [[FOR_NEXT_2:%.*]]
35 ; ANALYZE-FULL: do_store.2:
36 ; ANALYZE-FULL-NEXT: [[GEP_2:%.*]] = getelementptr i32, i32* [[A]], i32 2
37 ; ANALYZE-FULL-NEXT: store i32 2, i32* [[GEP_2]]
38 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_2]]
39 ; ANALYZE-FULL: for.next.2:
40 ; ANALYZE-FULL-NEXT: br i1 true, label [[DO_STORE_3:%.*]], label [[FOR_NEXT_3:%.*]]
41 ; ANALYZE-FULL: do_store.3:
42 ; ANALYZE-FULL-NEXT: [[GEP_3:%.*]] = getelementptr i32, i32* [[A]], i32 3
43 ; ANALYZE-FULL-NEXT: store i32 3, i32* [[GEP_3]]
44 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_3]]
45 ; ANALYZE-FULL: for.next.3:
46 ; ANALYZE-FULL-NEXT: br i1 false, label [[DO_STORE_4:%.*]], label [[FOR_NEXT_4:%.*]]
47 ; ANALYZE-FULL: do_store.4:
48 ; ANALYZE-FULL-NEXT: [[GEP_4:%.*]] = getelementptr i32, i32* [[A]], i32 4
49 ; ANALYZE-FULL-NEXT: store i32 4, i32* [[GEP_4]]
50 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_4]]
51 ; ANALYZE-FULL: for.next.4:
52 ; ANALYZE-FULL-NEXT: br i1 false, label [[DO_STORE_5:%.*]], label [[FOR_NEXT_5:%.*]]
53 ; ANALYZE-FULL: do_store.5:
54 ; ANALYZE-FULL-NEXT: [[GEP_5:%.*]] = getelementptr i32, i32* [[A]], i32 5
55 ; ANALYZE-FULL-NEXT: store i32 5, i32* [[GEP_5]]
56 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_5]]
57 ; ANALYZE-FULL: for.next.5:
58 ; ANALYZE-FULL-NEXT: br i1 false, label [[DO_STORE_6:%.*]], label [[FOR_NEXT_6:%.*]]
59 ; ANALYZE-FULL: do_store.6:
60 ; ANALYZE-FULL-NEXT: [[GEP_6:%.*]] = getelementptr i32, i32* [[A]], i32 6
61 ; ANALYZE-FULL-NEXT: store i32 6, i32* [[GEP_6]]
62 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_6]]
63 ; ANALYZE-FULL: for.next.6:
64 ; ANALYZE-FULL-NEXT: br i1 false, label [[DO_STORE_7:%.*]], label [[FOR_NEXT_7:%.*]]
65 ; ANALYZE-FULL: do_store.7:
66 ; ANALYZE-FULL-NEXT: [[GEP_7:%.*]] = getelementptr i32, i32* [[A]], i32 7
67 ; ANALYZE-FULL-NEXT: store i32 7, i32* [[GEP_7]]
68 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_7]]
69 ; ANALYZE-FULL: for.next.7:
70 ; ANALYZE-FULL-NEXT: br i1 false, label [[DO_STORE_8:%.*]], label [[FOR_NEXT_8:%.*]]
71 ; ANALYZE-FULL: do_store.8:
72 ; ANALYZE-FULL-NEXT: [[GEP_8:%.*]] = getelementptr i32, i32* [[A]], i32 8
73 ; ANALYZE-FULL-NEXT: store i32 8, i32* [[GEP_8]]
74 ; ANALYZE-FULL-NEXT: br label [[FOR_NEXT_8]]
75 ; ANALYZE-FULL: for.next.8:
76 ; ANALYZE-FULL-NEXT: ret i32 9
78 ; DONT-ANALYZE-FULL-LABEL: @foo(
79 ; DONT-ANALYZE-FULL-NEXT: entry:
80 ; DONT-ANALYZE-FULL-NEXT: br label [[FOR_BODY:%.*]]
81 ; DONT-ANALYZE-FULL: for.body:
82 ; DONT-ANALYZE-FULL-NEXT: [[INDVAR:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INDVAR_NEXT:%.*]], [[FOR_NEXT:%.*]] ]
83 ; DONT-ANALYZE-FULL-NEXT: [[INDVAR_NEXT]] = add i32 [[INDVAR]], 1
84 ; DONT-ANALYZE-FULL-NEXT: [[CMP:%.*]] = icmp ule i32 [[INDVAR]], 20
85 ; DONT-ANALYZE-FULL-NEXT: tail call void @llvm.assume(i1 [[CMP]])
86 ; DONT-ANALYZE-FULL-NEXT: [[CMP2:%.*]] = icmp ule i32 [[INDVAR]], 3
87 ; DONT-ANALYZE-FULL-NEXT: br i1 [[CMP2]], label [[DO_STORE:%.*]], label [[FOR_NEXT]]
88 ; DONT-ANALYZE-FULL: do_store:
89 ; DONT-ANALYZE-FULL-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[A:%.*]], i32 [[INDVAR]]
90 ; DONT-ANALYZE-FULL-NEXT: store i32 [[INDVAR]], i32* [[GEP]]
91 ; DONT-ANALYZE-FULL-NEXT: br label [[FOR_NEXT]]
92 ; DONT-ANALYZE-FULL: for.next:
93 ; DONT-ANALYZE-FULL-NEXT: [[EXITCOND:%.*]] = icmp ne i32 [[INDVAR_NEXT]], 9
94 ; DONT-ANALYZE-FULL-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[LOOPEXIT:%.*]]
95 ; DONT-ANALYZE-FULL: loopexit:
96 ; DONT-ANALYZE-FULL-NEXT: [[INDVAR_NEXT_LCSSA:%.*]] = phi i32 [ [[INDVAR_NEXT]], [[FOR_NEXT]] ]
97 ; DONT-ANALYZE-FULL-NEXT: ret i32 [[INDVAR_NEXT_LCSSA]]
102 %indvar = phi i32 [ 0, %entry ], [ %indvar.next, %for.next ]
103 %indvar.next = add i32 %indvar, 1
104 %cmp = icmp ule i32 %indvar, 20
105 tail call void @llvm.assume(i1 %cmp)
106 %cmp2 = icmp ule i32 %indvar, 3
107 br i1 %cmp2, label %do_store, label %for.next
110 %gep = getelementptr i32, i32* %a, i32 %indvar
111 store i32 %indvar, i32* %gep
115 %exitcond = icmp ne i32 %indvar.next, 9
116 br i1 %exitcond, label %for.body, label %loopexit