[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / OpenMP / unroll_codegen_tile_for.cpp
blobccfc9f38f5a241b3970191d0aa08ce9bcd377317
1 // Check code generation
2 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
4 // Check same results after serialization round-trip
5 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-pch -o %t %s
6 // RUN: %clang_cc1 -verify -triple x86_64-pc-linux-gnu -fopenmp -include-pch %t -emit-llvm %s -o - | FileCheck %s --check-prefix=IR
7 // expected-no-diagnostics
9 #ifndef HEADER
10 #define HEADER
12 // placeholder for loop body code.
13 extern "C" void body(...) {}
16 // IR-LABEL: @func(
17 // IR-NEXT: [[ENTRY:.*]]:
18 // IR-NEXT: %[[START_ADDR:.+]] = alloca i32, align 4
19 // IR-NEXT: %[[END_ADDR:.+]] = alloca i32, align 4
20 // IR-NEXT: %[[STEP_ADDR:.+]] = alloca i32, align 4
21 // IR-NEXT: %[[DOTOMP_IV:.+]] = alloca i32, align 4
22 // IR-NEXT: %[[TMP:.+]] = alloca i32, align 4
23 // IR-NEXT: %[[I:.+]] = alloca i32, align 4
24 // IR-NEXT: %[[DOTCAPTURE_EXPR_:.+]] = alloca i32, align 4
25 // IR-NEXT: %[[DOTCAPTURE_EXPR_1:.+]] = alloca i32, align 4
26 // IR-NEXT: %[[DOTCAPTURE_EXPR_2:.+]] = alloca i32, align 4
27 // IR-NEXT: %[[DOTCAPTURE_EXPR_3:.+]] = alloca i32, align 4
28 // IR-NEXT: %[[DOTUNROLLED_IV_I:.+]] = alloca i32, align 4
29 // IR-NEXT: %[[DOTCAPTURE_EXPR_6:.+]] = alloca i32, align 4
30 // IR-NEXT: %[[DOTCAPTURE_EXPR_8:.+]] = alloca i32, align 4
31 // IR-NEXT: %[[DOTCAPTURE_EXPR_12:.+]] = alloca i32, align 4
32 // IR-NEXT: %[[DOTCAPTURE_EXPR_14:.+]] = alloca i32, align 4
33 // IR-NEXT: %[[DOTFLOOR_0_IV__UNROLLED_IV_I:.+]] = alloca i32, align 4
34 // IR-NEXT: %[[DOTOMP_LB:.+]] = alloca i32, align 4
35 // IR-NEXT: %[[DOTOMP_UB:.+]] = alloca i32, align 4
36 // IR-NEXT: %[[DOTOMP_STRIDE:.+]] = alloca i32, align 4
37 // IR-NEXT: %[[DOTOMP_IS_LAST:.+]] = alloca i32, align 4
38 // IR-NEXT: %[[DOTFLOOR_0_IV__UNROLLED_IV_I18:.+]] = alloca i32, align 4
39 // IR-NEXT: %[[DOTTILE_0_IV__UNROLLED_IV_I:.+]] = alloca i32, align 4
40 // IR-NEXT: %[[DOTUNROLL_INNER_IV_I:.+]] = alloca i32, align 4
41 // IR-NEXT: %[[TMP0:.+]] = call i32 @__kmpc_global_thread_num(ptr @2)
42 // IR-NEXT: store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
43 // IR-NEXT: store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
44 // IR-NEXT: store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
45 // IR-NEXT: %[[TMP1:.+]] = load i32, ptr %[[START_ADDR]], align 4
46 // IR-NEXT: store i32 %[[TMP1]], ptr %[[I]], align 4
47 // IR-NEXT: %[[TMP2:.+]] = load i32, ptr %[[START_ADDR]], align 4
48 // IR-NEXT: store i32 %[[TMP2]], ptr %[[DOTCAPTURE_EXPR_]], align 4
49 // IR-NEXT: %[[TMP3:.+]] = load i32, ptr %[[END_ADDR]], align 4
50 // IR-NEXT: store i32 %[[TMP3]], ptr %[[DOTCAPTURE_EXPR_1]], align 4
51 // IR-NEXT: %[[TMP4:.+]] = load i32, ptr %[[STEP_ADDR]], align 4
52 // IR-NEXT: store i32 %[[TMP4]], ptr %[[DOTCAPTURE_EXPR_2]], align 4
53 // IR-NEXT: %[[TMP5:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_1]], align 4
54 // IR-NEXT: %[[TMP6:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_]], align 4
55 // IR-NEXT: %[[SUB:.+]] = sub i32 %[[TMP5]], %[[TMP6]]
56 // IR-NEXT: %[[SUB4:.+]] = sub i32 %[[SUB]], 1
57 // IR-NEXT: %[[TMP7:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_2]], align 4
58 // IR-NEXT: %[[ADD:.+]] = add i32 %[[SUB4]], %[[TMP7]]
59 // IR-NEXT: %[[TMP8:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_2]], align 4
60 // IR-NEXT: %[[DIV:.+]] = udiv i32 %[[ADD]], %[[TMP8]]
61 // IR-NEXT: %[[SUB5:.+]] = sub i32 %[[DIV]], 1
62 // IR-NEXT: store i32 %[[SUB5]], ptr %[[DOTCAPTURE_EXPR_3]], align 4
63 // IR-NEXT: store i32 0, ptr %[[DOTUNROLLED_IV_I]], align 4
64 // IR-NEXT: %[[TMP9:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_3]], align 4
65 // IR-NEXT: %[[ADD7:.+]] = add i32 %[[TMP9]], 1
66 // IR-NEXT: store i32 %[[ADD7]], ptr %[[DOTCAPTURE_EXPR_6]], align 4
67 // IR-NEXT: %[[TMP10:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_6]], align 4
68 // IR-NEXT: %[[SUB9:.+]] = sub i32 %[[TMP10]], -1
69 // IR-NEXT: %[[DIV10:.+]] = udiv i32 %[[SUB9]], 2
70 // IR-NEXT: %[[SUB11:.+]] = sub i32 %[[DIV10]], 1
71 // IR-NEXT: store i32 %[[SUB11]], ptr %[[DOTCAPTURE_EXPR_8]], align 4
72 // IR-NEXT: %[[TMP11:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_8]], align 4
73 // IR-NEXT: %[[ADD13:.+]] = add i32 %[[TMP11]], 1
74 // IR-NEXT: store i32 %[[ADD13]], ptr %[[DOTCAPTURE_EXPR_12]], align 4
75 // IR-NEXT: %[[TMP12:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_12]], align 4
76 // IR-NEXT: %[[SUB15:.+]] = sub i32 %[[TMP12]], -3
77 // IR-NEXT: %[[DIV16:.+]] = udiv i32 %[[SUB15]], 4
78 // IR-NEXT: %[[SUB17:.+]] = sub i32 %[[DIV16]], 1
79 // IR-NEXT: store i32 %[[SUB17]], ptr %[[DOTCAPTURE_EXPR_14]], align 4
80 // IR-NEXT: store i32 0, ptr %[[DOTFLOOR_0_IV__UNROLLED_IV_I]], align 4
81 // IR-NEXT: %[[TMP13:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_12]], align 4
82 // IR-NEXT: %[[CMP:.+]] = icmp ult i32 0, %[[TMP13]]
83 // IR-NEXT: br i1 %[[CMP]], label %[[OMP_PRECOND_THEN:.+]], label %[[OMP_PRECOND_END:.+]]
84 // IR-EMPTY:
85 // IR-NEXT: [[OMP_PRECOND_THEN]]:
86 // IR-NEXT: store i32 0, ptr %[[DOTOMP_LB]], align 4
87 // IR-NEXT: %[[TMP14:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_14]], align 4
88 // IR-NEXT: store i32 %[[TMP14]], ptr %[[DOTOMP_UB]], align 4
89 // IR-NEXT: store i32 1, ptr %[[DOTOMP_STRIDE]], align 4
90 // IR-NEXT: store i32 0, ptr %[[DOTOMP_IS_LAST]], align 4
91 // IR-NEXT: call void @__kmpc_for_static_init_4u(ptr @1, i32 %[[TMP0]], i32 34, ptr %[[DOTOMP_IS_LAST]], ptr %[[DOTOMP_LB]], ptr %[[DOTOMP_UB]], ptr %[[DOTOMP_STRIDE]], i32 1, i32 1)
92 // IR-NEXT: %[[TMP15:.+]] = load i32, ptr %[[DOTOMP_UB]], align 4
93 // IR-NEXT: %[[TMP16:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_14]], align 4
94 // IR-NEXT: %[[CMP19:.+]] = icmp ugt i32 %[[TMP15]], %[[TMP16]]
95 // IR-NEXT: br i1 %[[CMP19]], label %[[COND_TRUE:.+]], label %[[COND_FALSE:.+]]
96 // IR-EMPTY:
97 // IR-NEXT: [[COND_TRUE]]:
98 // IR-NEXT: %[[TMP17:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_14]], align 4
99 // IR-NEXT: br label %[[COND_END:.+]]
100 // IR-EMPTY:
101 // IR-NEXT: [[COND_FALSE]]:
102 // IR-NEXT: %[[TMP18:.+]] = load i32, ptr %[[DOTOMP_UB]], align 4
103 // IR-NEXT: br label %[[COND_END]]
104 // IR-EMPTY:
105 // IR-NEXT: [[COND_END]]:
106 // IR-NEXT: %[[COND:.+]] = phi i32 [ %[[TMP17]], %[[COND_TRUE]] ], [ %[[TMP18]], %[[COND_FALSE]] ]
107 // IR-NEXT: store i32 %[[COND]], ptr %[[DOTOMP_UB]], align 4
108 // IR-NEXT: %[[TMP19:.+]] = load i32, ptr %[[DOTOMP_LB]], align 4
109 // IR-NEXT: store i32 %[[TMP19]], ptr %[[DOTOMP_IV]], align 4
110 // IR-NEXT: br label %[[OMP_INNER_FOR_COND:.+]]
111 // IR-EMPTY:
112 // IR-NEXT: [[OMP_INNER_FOR_COND]]:
113 // IR-NEXT: %[[TMP20:.+]] = load i32, ptr %[[DOTOMP_IV]], align 4
114 // IR-NEXT: %[[TMP21:.+]] = load i32, ptr %[[DOTOMP_UB]], align 4
115 // IR-NEXT: %[[ADD20:.+]] = add i32 %[[TMP21]], 1
116 // IR-NEXT: %[[CMP21:.+]] = icmp ult i32 %[[TMP20]], %[[ADD20]]
117 // IR-NEXT: br i1 %[[CMP21]], label %[[OMP_INNER_FOR_BODY:.+]], label %[[OMP_INNER_FOR_END:.+]]
118 // IR-EMPTY:
119 // IR-NEXT: [[OMP_INNER_FOR_BODY]]:
120 // IR-NEXT: %[[TMP22:.+]] = load i32, ptr %[[DOTOMP_IV]], align 4
121 // IR-NEXT: %[[MUL:.+]] = mul i32 %[[TMP22]], 4
122 // IR-NEXT: %[[ADD22:.+]] = add i32 0, %[[MUL]]
123 // IR-NEXT: store i32 %[[ADD22]], ptr %[[DOTFLOOR_0_IV__UNROLLED_IV_I18]], align 4
124 // IR-NEXT: %[[TMP23:.+]] = load i32, ptr %[[DOTFLOOR_0_IV__UNROLLED_IV_I18]], align 4
125 // IR-NEXT: store i32 %[[TMP23]], ptr %[[DOTTILE_0_IV__UNROLLED_IV_I]], align 4
126 // IR-NEXT: br label %[[FOR_COND:.+]]
127 // IR-EMPTY:
128 // IR-NEXT: [[FOR_COND]]:
129 // IR-NEXT: %[[TMP24:.+]] = load i32, ptr %[[DOTTILE_0_IV__UNROLLED_IV_I]], align 4
130 // IR-NEXT: %[[TMP25:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_8]], align 4
131 // IR-NEXT: %[[ADD23:.+]] = add i32 %[[TMP25]], 1
132 // IR-NEXT: %[[TMP26:.+]] = load i32, ptr %[[DOTFLOOR_0_IV__UNROLLED_IV_I18]], align 4
133 // IR-NEXT: %[[ADD24:.+]] = add i32 %[[TMP26]], 4
134 // IR-NEXT: %[[CMP25:.+]] = icmp ult i32 %[[ADD23]], %[[ADD24]]
135 // IR-NEXT: br i1 %[[CMP25]], label %[[COND_TRUE26:.+]], label %[[COND_FALSE28:.+]]
136 // IR-EMPTY:
137 // IR-NEXT: [[COND_TRUE26]]:
138 // IR-NEXT: %[[TMP27:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_8]], align 4
139 // IR-NEXT: %[[ADD27:.+]] = add i32 %[[TMP27]], 1
140 // IR-NEXT: br label %[[COND_END30:.+]]
141 // IR-EMPTY:
142 // IR-NEXT: [[COND_FALSE28]]:
143 // IR-NEXT: %[[TMP28:.+]] = load i32, ptr %[[DOTFLOOR_0_IV__UNROLLED_IV_I18]], align 4
144 // IR-NEXT: %[[ADD29:.+]] = add i32 %[[TMP28]], 4
145 // IR-NEXT: br label %[[COND_END30]]
146 // IR-EMPTY:
147 // IR-NEXT: [[COND_END30]]:
148 // IR-NEXT: %[[COND31:.+]] = phi i32 [ %[[ADD27]], %[[COND_TRUE26]] ], [ %[[ADD29]], %[[COND_FALSE28]] ]
149 // IR-NEXT: %[[CMP32:.+]] = icmp ult i32 %[[TMP24]], %[[COND31]]
150 // IR-NEXT: br i1 %[[CMP32]], label %[[FOR_BODY:.+]], label %[[FOR_END45:.+]]
151 // IR-EMPTY:
152 // IR-NEXT: [[FOR_BODY]]:
153 // IR-NEXT: %[[TMP29:.+]] = load i32, ptr %[[DOTTILE_0_IV__UNROLLED_IV_I]], align 4
154 // IR-NEXT: %[[MUL33:.+]] = mul i32 %[[TMP29]], 2
155 // IR-NEXT: %[[ADD34:.+]] = add i32 0, %[[MUL33]]
156 // IR-NEXT: store i32 %[[ADD34]], ptr %[[DOTUNROLLED_IV_I]], align 4
157 // IR-NEXT: %[[TMP30:.+]] = load i32, ptr %[[DOTUNROLLED_IV_I]], align 4
158 // IR-NEXT: store i32 %[[TMP30]], ptr %[[DOTUNROLL_INNER_IV_I]], align 4
159 // IR-NEXT: br label %[[FOR_COND35:.+]]
160 // IR-EMPTY:
161 // IR-NEXT: [[FOR_COND35]]:
162 // IR-NEXT: %[[TMP31:.+]] = load i32, ptr %[[DOTUNROLL_INNER_IV_I]], align 4
163 // IR-NEXT: %[[TMP32:.+]] = load i32, ptr %[[DOTUNROLLED_IV_I]], align 4
164 // IR-NEXT: %[[ADD36:.+]] = add i32 %[[TMP32]], 2
165 // IR-NEXT: %[[CMP37:.+]] = icmp ult i32 %[[TMP31]], %[[ADD36]]
166 // IR-NEXT: br i1 %[[CMP37]], label %[[LAND_RHS:.+]], label %[[LAND_END:.+]]
167 // IR-EMPTY:
168 // IR-NEXT: [[LAND_RHS]]:
169 // IR-NEXT: %[[TMP33:.+]] = load i32, ptr %[[DOTUNROLL_INNER_IV_I]], align 4
170 // IR-NEXT: %[[TMP34:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_3]], align 4
171 // IR-NEXT: %[[ADD38:.+]] = add i32 %[[TMP34]], 1
172 // IR-NEXT: %[[CMP39:.+]] = icmp ult i32 %[[TMP33]], %[[ADD38]]
173 // IR-NEXT: br label %[[LAND_END]]
174 // IR-EMPTY:
175 // IR-NEXT: [[LAND_END]]:
176 // IR-NEXT: %[[TMP35:.+]] = phi i1 [ false, %[[FOR_COND35]] ], [ %[[CMP39]], %[[LAND_RHS]] ]
177 // IR-NEXT: br i1 %[[TMP35]], label %[[FOR_BODY40:.+]], label %[[FOR_END:.+]]
178 // IR-EMPTY:
179 // IR-NEXT: [[FOR_BODY40]]:
180 // IR-NEXT: %[[TMP36:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_]], align 4
181 // IR-NEXT: %[[TMP37:.+]] = load i32, ptr %[[DOTUNROLL_INNER_IV_I]], align 4
182 // IR-NEXT: %[[TMP38:.+]] = load i32, ptr %[[DOTCAPTURE_EXPR_2]], align 4
183 // IR-NEXT: %[[MUL41:.+]] = mul i32 %[[TMP37]], %[[TMP38]]
184 // IR-NEXT: %[[ADD42:.+]] = add i32 %[[TMP36]], %[[MUL41]]
185 // IR-NEXT: store i32 %[[ADD42]], ptr %[[I]], align 4
186 // IR-NEXT: %[[TMP39:.+]] = load i32, ptr %[[START_ADDR]], align 4
187 // IR-NEXT: %[[TMP40:.+]] = load i32, ptr %[[END_ADDR]], align 4
188 // IR-NEXT: %[[TMP41:.+]] = load i32, ptr %[[STEP_ADDR]], align 4
189 // IR-NEXT: %[[TMP42:.+]] = load i32, ptr %[[I]], align 4
190 // IR-NEXT: call void (...) @body(i32 noundef %[[TMP39]], i32 noundef %[[TMP40]], i32 noundef %[[TMP41]], i32 noundef %[[TMP42]])
191 // IR-NEXT: br label %[[FOR_INC:.+]]
192 // IR-EMPTY:
193 // IR-NEXT: [[FOR_INC]]:
194 // IR-NEXT: %[[TMP43:.+]] = load i32, ptr %[[DOTUNROLL_INNER_IV_I]], align 4
195 // IR-NEXT: %[[INC:.+]] = add i32 %[[TMP43]], 1
196 // IR-NEXT: store i32 %[[INC]], ptr %[[DOTUNROLL_INNER_IV_I]], align 4
197 // IR-NEXT: br label %[[FOR_COND35]], !llvm.loop ![[LOOP2:[0-9]+]]
198 // IR-EMPTY:
199 // IR-NEXT: [[FOR_END]]:
200 // IR-NEXT: br label %[[FOR_INC43:.+]]
201 // IR-EMPTY:
202 // IR-NEXT: [[FOR_INC43]]:
203 // IR-NEXT: %[[TMP44:.+]] = load i32, ptr %[[DOTTILE_0_IV__UNROLLED_IV_I]], align 4
204 // IR-NEXT: %[[INC44:.+]] = add i32 %[[TMP44]], 1
205 // IR-NEXT: store i32 %[[INC44]], ptr %[[DOTTILE_0_IV__UNROLLED_IV_I]], align 4
206 // IR-NEXT: br label %[[FOR_COND]], !llvm.loop ![[LOOP5:[0-9]+]]
207 // IR-EMPTY:
208 // IR-NEXT: [[FOR_END45]]:
209 // IR-NEXT: br label %[[OMP_BODY_CONTINUE:.+]]
210 // IR-EMPTY:
211 // IR-NEXT: [[OMP_BODY_CONTINUE]]:
212 // IR-NEXT: br label %[[OMP_INNER_FOR_INC:.+]]
213 // IR-EMPTY:
214 // IR-NEXT: [[OMP_INNER_FOR_INC]]:
215 // IR-NEXT: %[[TMP45:.+]] = load i32, ptr %[[DOTOMP_IV]], align 4
216 // IR-NEXT: %[[ADD46:.+]] = add i32 %[[TMP45]], 1
217 // IR-NEXT: store i32 %[[ADD46]], ptr %[[DOTOMP_IV]], align 4
218 // IR-NEXT: br label %[[OMP_INNER_FOR_COND]]
219 // IR-EMPTY:
220 // IR-NEXT: [[OMP_INNER_FOR_END]]:
221 // IR-NEXT: br label %[[OMP_LOOP_EXIT:.+]]
222 // IR-EMPTY:
223 // IR-NEXT: [[OMP_LOOP_EXIT]]:
224 // IR-NEXT: call void @__kmpc_for_static_fini(ptr @1, i32 %[[TMP0]])
225 // IR-NEXT: br label %[[OMP_PRECOND_END]]
226 // IR-EMPTY:
227 // IR-NEXT: [[OMP_PRECOND_END]]:
228 // IR-NEXT: call void @__kmpc_barrier(ptr @3, i32 %[[TMP0]])
229 // IR-NEXT: ret void
230 // IR-NEXT: }
231 extern "C" void func(int start, int end, int step) {
232 #pragma omp for
233 #pragma omp tile sizes(4)
234 #pragma omp unroll partial
235 for (int i = start; i < end; i+=step)
236 body(start, end, step, i);
239 #endif /* HEADER */
242 // IR: ![[LOOP2]] = distinct !{![[LOOP2]], ![[LOOPPROP3:[0-9]+]], ![[LOOPPROP4:[0-9]+]]}
243 // IR: ![[LOOPPROP3]] = !{!"llvm.loop.mustprogress"}
244 // IR: ![[LOOPPROP4]] = !{!"llvm.loop.unroll.count", i32 2}
245 // IR: ![[LOOP5]] = distinct !{![[LOOP5]], ![[LOOPPROP3]]}