1 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fopenmp-version=45 | FileCheck %s
2 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s -fopenmp-version=45
3 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s
4 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - -fopenmp-version=45 | FileCheck %s --check-prefix=TERM_DEBUG
5 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50 --check-prefix=OMP50RT
6 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s -fopenmp-version=50 -DOMP5
7 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50 --check-prefix=OMP50RT
8 
9 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fopenmp-version=45 | FileCheck %s
10 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s -fopenmp-version=45
11 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=45 | FileCheck %s
12 // RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - -fopenmp-version=45 | FileCheck --check-prefix=TERM_DEBUG %s
13 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
14 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s -fopenmp-version=50 -DOMP5
15 // RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - -fopenmp-version=50 -DOMP5 | FileCheck %s --check-prefix=CHECK --check-prefix=OMP50
16 // expected-no-diagnostics
17  #ifndef HEADER
18  #define HEADER
19 
20 #ifdef OMP5
21 #define CONDITIONAL conditional :
22 #else
23 #define CONDITIONAL
24 #endif //OMP5
25 // CHECK: [[SS_TY:%.+]] = type { i32 }
26 // OMP50-DAG: [[LAST_IV:@.+]] = {{.*}}common global i64 0
27 // OMP50-DAG: [[LAST_A:@.+]] = {{.*}}common global i32 0
28 
get_val()29 long long get_val() { extern void mayThrow(); mayThrow(); return 0; }
30 double *g_ptr;
31 
32 struct S {
33   int a, b;
34 };
35 
36 // CHECK-LABEL: define {{.*void}} @{{.*}}simple{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
simple(float * a,float * b,float * c,float * d)37 void simple(float *a, float *b, float *c, float *d) {
38   S s, *p;
39 #ifdef OMP5
40   #pragma omp simd if (simd: true) nontemporal(a, b, c, d, s)
41 #else
42   #pragma omp simd
43 #endif
44   // CHECK: store i32 0, i32* [[OMP_IV:%[^,]+]]
45 
46 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
47 // CHECK-NEXT: [[CMP:%.+]] = icmp slt i32 [[IV]], 6
48 // CHECK-NEXT: br i1 [[CMP]], label %[[SIMPLE_LOOP1_BODY:.+]], label %[[SIMPLE_LOOP1_END:[^,]+]]
49   for (int i = 3; i < 32; i += 5) {
50 // CHECK: [[SIMPLE_LOOP1_BODY]]:
51 // Start of body: calculate i from IV:
52 // CHECK: [[IV1_1:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
53 // CHECK: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 5
54 // CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 3, [[CALC_I_1]]
55 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]{{.*}}!llvm.access.group
56 // ... loop body ...
57 // End of body: store into a[i]:
58 // OMP45-NOT: load float*,{{.*}}!nontemporal
59 // CHECK-NOT: load float,{{.*}}!nontemporal
60 // OMP50: load float*,{{.*}}!nontemporal
61 // OMP50: load float*,{{.*}}!nontemporal
62 // OMP50: load float*,{{.*}}!nontemporal
63 // OMP50: load i32,{{.*}}!nontemporal
64 // OMP50-NOT: load i32,{{.*}}!nontemporal
65 // OMP50: load float*,{{.*}}!nontemporal
66 // CHECK-NOT: load float,{{.*}}!nontemporal
67 // CHECK: store float [[RESULT:%.+]], float* {{%.+}}{{.*}}!llvm.access.group
68     a[i] = b[i] * c[i] * d[i] + s.a + p->a;
69 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
70 // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
71 // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]{{.*}}!llvm.access.group
72 // br label %{{.+}}, !llvm.loop !{{.+}}
73   }
74 // CHECK: [[SIMPLE_LOOP1_END]]:
75 
76   long long k = get_val();
77 
78   #pragma omp simd linear(k : 3)
79 // CHECK: [[K0:%.+]] = call {{.*}}i64 @{{.*}}get_val
80 // CHECK-NEXT: store i64 [[K0]], i64* [[K_VAR:%[^,]+]]
81 // CHECK: store i32 0, i32* [[OMP_IV2:%[^,]+]]
82 // CHECK: [[K0LOAD:%.+]] = load i64, i64* [[K_VAR]]
83 // CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
84 
85 // CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
86 // CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV2]], 9
87 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP2_BODY:.+]], label %[[SIMPLE_LOOP2_END:[^,]+]]
88   for (int i = 10; i > 1; i--) {
89 // CHECK: [[SIMPLE_LOOP2_BODY]]:
90 // Start of body: calculate i from IV:
91 // CHECK: [[IV2_0:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
92 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
93 // CHECK-NEXT: [[IV2_1:%.+]] = mul nsw i32 [[IV2_0]], 1
94 // CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV2_1]]
95 // CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.access.group
96 //
97 // CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.access.group
98 // CHECK-NEXT: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
99 // CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV2_2]], 3
100 // CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
101 // CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
102 // Update of the privatized version of linear variable!
103 // CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
104     a[k]++;
105     k = k + 3;
106 // CHECK: [[IV2_2:%.+]] = load i32, i32* [[OMP_IV2]]{{.*}}!llvm.access.group
107 // CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV2_2]], 1
108 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV2]]{{.*}}!llvm.access.group
109 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP2_ID]]
110   }
111 // CHECK: [[SIMPLE_LOOP2_END]]:
112 //
113 // Update linear vars after loop, as the loop was operating on a private version.
114 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
115 // CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
116 // CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[K_VAR]]
117 //
118 
119   int lin = 12;
120   #pragma omp simd linear(lin : get_val()), linear(g_ptr)
121 
122 // Init linear private var.
123 // CHECK: store i32 12, i32* [[LIN_VAR:%[^,]+]]
124 // CHECK: store i64 0, i64* [[OMP_IV3:%[^,]+]]
125 
126 // CHECK: [[LIN_LOAD:%.+]] = load i32, i32* [[LIN_VAR]]
127 // CHECK-NEXT: store i32 [[LIN_LOAD]], i32* [[LIN_START:%[^,]+]]
128 // Remember linear step.
129 // CHECK: [[CALL_VAL:%.+]] = invoke
130 // CHECK: store i64 [[CALL_VAL]], i64* [[LIN_STEP:%[^,]+]]
131 
132 // CHECK: [[GLIN_LOAD:%.+]] = load double*, double** [[GLIN_VAR:@[^,]+]]
133 // CHECK-NEXT: store double* [[GLIN_LOAD]], double** [[GLIN_START:%[^,]+]]
134 
135 // CHECK: [[IV3:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.access.group
136 // CHECK-NEXT: [[CMP3:%.+]] = icmp ult i64 [[IV3]], 4
137 // CHECK-NEXT: br i1 [[CMP3]], label %[[SIMPLE_LOOP3_BODY:.+]], label %[[SIMPLE_LOOP3_END:[^,]+]]
138   for (unsigned long long it = 2000; it >= 600; it-=400) {
139 // CHECK: [[SIMPLE_LOOP3_BODY]]:
140 // Start of body: calculate it from IV:
141 // CHECK: [[IV3_0:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.access.group
142 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul i64 [[IV3_0]], 400
143 // CHECK-NEXT: [[LC_IT_2:%.+]] = sub i64 2000, [[LC_IT_1]]
144 // CHECK-NEXT: store i64 [[LC_IT_2]], i64* {{.+}}, !llvm.access.group
145 //
146 // Linear start and step are used to calculate current value of the linear variable.
147 // CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]{{.*}}!llvm.access.group
148 // CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]{{.*}}!llvm.access.group
149 // CHECK-NOT: store i32 {{.+}}, i32* [[LIN_VAR]],{{.*}}!llvm.access.group
150 // CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]{{.*}}!llvm.access.group
151 // CHECK-NEXT: [[IV3_1:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.access.group
152 // CHECK-NEXT: [[MUL:%.+]] = mul i64 [[IV3_1]], 1
153 // CHECK: [[GEP:%.+]] = getelementptr{{.*}}[[GLINSTART]]
154 // CHECK-NEXT: store double* [[GEP]], double** [[G_PTR_CUR:%[^,]+]]{{.*}}!llvm.access.group
155     *g_ptr++ = 0.0;
156 // CHECK: [[GEP_VAL:%.+]] = load double{{.*}}[[G_PTR_CUR]]{{.*}}!llvm.access.group
157 // CHECK: store double{{.*}}[[GEP_VAL]]{{.*}}!llvm.access.group
158     a[it + lin]++;
159 // CHECK: [[FLT_INC:%.+]] = fadd float
160 // CHECK-NEXT: store float [[FLT_INC]],{{.*}}!llvm.access.group
161 // CHECK: [[IV3_2:%.+]] = load i64, i64* [[OMP_IV3]]{{.*}}!llvm.access.group
162 // CHECK-NEXT: [[ADD3_2:%.+]] = add i64 [[IV3_2]], 1
163 // CHECK-NEXT: store i64 [[ADD3_2]], i64* [[OMP_IV3]]{{.*}}!llvm.access.group
164   }
165 // CHECK: [[SIMPLE_LOOP3_END]]:
166 //
167 // Linear start and step are used to calculate final value of the linear variables.
168 // CHECK: [[LINSTART:.+]] = load i32, i32* [[LIN_START]]
169 // CHECK: [[LINSTEP:.+]] = load i64, i64* [[LIN_STEP]]
170 // CHECK: store i32 {{.+}}, i32* [[LIN_VAR]],
171 // CHECK: [[GLINSTART:.+]] = load double*, double** [[GLIN_START]]
172 // CHECK: store double* {{.*}}[[GLIN_VAR]]
173 
174   #pragma omp simd
175 // CHECK: store i32 0, i32* [[OMP_IV4:%[^,]+]]
176 
177 // CHECK: [[IV4:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.access.group
178 // CHECK-NEXT: [[CMP4:%.+]] = icmp slt i32 [[IV4]], 4
179 // CHECK-NEXT: br i1 [[CMP4]], label %[[SIMPLE_LOOP4_BODY:.+]], label %[[SIMPLE_LOOP4_END:[^,]+]]
180   for (short it = 6; it <= 20; it-=-4) {
181 // CHECK: [[SIMPLE_LOOP4_BODY]]:
182 // Start of body: calculate it from IV:
183 // CHECK: [[IV4_0:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.access.group
184 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i32 [[IV4_0]], 4
185 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i32 6, [[LC_IT_1]]
186 // CHECK-NEXT: [[LC_IT_3:%.+]] = trunc i32 [[LC_IT_2]] to i16
187 // CHECK-NEXT: store i16 [[LC_IT_3]], i16* {{.+}}, !llvm.access.group
188 
189 // CHECK: [[IV4_2:%.+]] = load i32, i32* [[OMP_IV4]]{{.*}}!llvm.access.group
190 // CHECK-NEXT: [[ADD4_2:%.+]] = add nsw i32 [[IV4_2]], 1
191 // CHECK-NEXT: store i32 [[ADD4_2]], i32* [[OMP_IV4]]{{.*}}!llvm.access.group
192   }
193 // CHECK: [[SIMPLE_LOOP4_END]]:
194 
195   #pragma omp simd
196 // CHECK: store i32 0, i32* [[OMP_IV5:%[^,]+]]
197 
198 // CHECK: [[IV5:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.access.group
199 // CHECK-NEXT: [[CMP5:%.+]] = icmp slt i32 [[IV5]], 26
200 // CHECK-NEXT: br i1 [[CMP5]], label %[[SIMPLE_LOOP5_BODY:.+]], label %[[SIMPLE_LOOP5_END:[^,]+]]
201   for (unsigned char it = 'z'; it >= 'a'; it+=-1) {
202 // CHECK: [[SIMPLE_LOOP5_BODY]]:
203 // Start of body: calculate it from IV:
204 // CHECK: [[IV5_0:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.access.group
205 // CHECK-NEXT: [[IV5_1:%.+]] = mul nsw i32 [[IV5_0]], 1
206 // CHECK-NEXT: [[LC_IT_1:%.+]] = sub nsw i32 122, [[IV5_1]]
207 // CHECK-NEXT: [[LC_IT_2:%.+]] = trunc i32 [[LC_IT_1]] to i8
208 // CHECK-NEXT: store i8 [[LC_IT_2]], i8* {{.+}}, !llvm.access.group
209 
210 // CHECK: [[IV5_2:%.+]] = load i32, i32* [[OMP_IV5]]{{.*}}!llvm.access.group
211 // CHECK-NEXT: [[ADD5_2:%.+]] = add nsw i32 [[IV5_2]], 1
212 // CHECK-NEXT: store i32 [[ADD5_2]], i32* [[OMP_IV5]]{{.*}}!llvm.access.group
213   }
214 // CHECK: [[SIMPLE_LOOP5_END]]:
215 
216 // CHECK-NOT: mul i32 %{{.+}}, 10
217   #pragma omp simd
218   for (unsigned i=100; i<10; i+=10) {
219   }
220 
221   int A;
222   // CHECK: store i32 -1, i32* [[A:%.+]],
223   A = -1;
224   #pragma omp simd lastprivate(CONDITIONAL A)
225 // CHECK: store i64 0, i64* [[OMP_IV7:%[^,]+]]
226 // CHECK: br label %[[SIMD_LOOP7_COND:[^,]+]]
227 // CHECK: [[SIMD_LOOP7_COND]]:
228 // CHECK-NEXT: [[IV7:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.access.group
229 // CHECK-NEXT: [[CMP7:%.+]] = icmp slt i64 [[IV7]], 7
230 // CHECK-NEXT: br i1 [[CMP7]], label %[[SIMPLE_LOOP7_BODY:.+]], label %[[SIMPLE_LOOP7_END:[^,]+]]
231   for (long long i = -10; i < 10; i += 3) {
232 // CHECK: [[SIMPLE_LOOP7_BODY]]:
233 // Start of body: calculate i from IV:
234 // CHECK: [[IV7_0:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.access.group
235 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV7_0]], 3
236 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
237 // CHECK-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],{{.+}}!llvm.access.group
238 // CHECK-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]]{{.+}}!llvm.access.group
239 // CHECK-NEXT: [[A_VAL:%.+]] = load i32, i32* [[A_PRIV:%[^,]+]],{{.+}}!llvm.access.group
240 // CHECK-NEXT: [[CAST:%.+]] = sext i32 [[A_VAL]] to i64
241 // CHECK-NEXT: [[ADD:%.+]] = add nsw i64 [[CAST]], [[LC_VAL]]
242 // CHECK-NEXT: [[CONV:%.+]] = trunc i64 [[ADD]] to i32
243 // CHECK-NEXT: store i32 [[CONV]], i32* [[A_PRIV]],{{.+}}!llvm.access.group
244 // OMP50-NEXT: [[IV:%.+]] = load i64, i64* [[OMP_IV7]],{{.+}}!llvm.access.group
245 // OMP50RT:    call void @__kmpc_critical(%struct.ident_t* {{.+}}, i32 [[GTID:%.+]], [8 x i32]* [[A_REGION:@.+]]),{{.+}}!llvm.access.group
246 // OMP50-NEXT: [[LAST_IV_VAL:%.+]] = load i64, i64* [[LAST_IV]],{{.+}}!llvm.access.group
247 // OMP50-NEXT: [[CMP:%.+]] = icmp sle i64 [[LAST_IV_VAL]], [[IV]]
248 // OMP50-NEXT: br i1 [[CMP]], label %[[LP_THEN:.+]], label %[[LP_DONE:[^,]+]]
249 // OMP50:      [[LP_THEN]]:
250 // OMP50-NEXT: store i64 [[IV]], i64* [[LAST_IV]],{{.+}}!llvm.access.group
251 // OMP50-NEXT: [[A_VAL:%.+]] = load i32, i32* [[A_PRIV]],{{.+}}!llvm.access.group
252 // OMP50-NEXT: store i32 [[A_VAL]], i32* [[LAST_A]],{{.+}}!llvm.access.group
253 // OMP50-NEXT: br label %[[LP_DONE]]
254 // OMP50:      [[LP_DONE]]:
255 // OMP50RT-NEXT: call void @__kmpc_end_critical(%struct.ident_t* {{.+}}, i32 [[GTID]], [8 x i32]* [[A_REGION]]),{{.+}}!llvm.access.group
256     A += i;
257 // CHECK: [[IV7_2:%.+]] = load i64, i64* [[OMP_IV7]]{{.*}}!llvm.access.group
258 // CHECK-NEXT: [[ADD7_2:%.+]] = add nsw i64 [[IV7_2]], 1
259 // CHECK-NEXT: store i64 [[ADD7_2]], i64* [[OMP_IV7]]{{.*}}!llvm.access.group
260   }
261 // CHECK: [[SIMPLE_LOOP7_END]]:
262 // CHECK-NEXT: store i64 11, i64*
263 // OMP50-NEXT: [[LAST_A_VAL:%.+]] = load i32, i32* [[LAST_A]],
264 // OMP50-NEXT: store i32 [[LAST_A_VAL]], i32* [[A_PRIV]],
265 // CHECK-NEXT: [[A_PRIV_VAL:%.+]] = load i32, i32* [[A_PRIV]],
266 // CHECK-NEXT: store i32 [[A_PRIV_VAL]], i32* [[A]],
267   int R;
268   // CHECK: store i32 -1, i32* [[R:%[^,]+]],
269   R = -1;
270 // CHECK: store i64 0, i64* [[OMP_IV8:%[^,]+]],
271 // CHECK: store i32 1, i32* [[R_PRIV:%[^,]+]],
272 #ifdef OMP5
273   #pragma omp simd reduction(*:R) if(A)
274 #else
275   #pragma omp simd reduction(*:R)
276 #endif
277 // OMP50:      [[A_VAL:%.+]] = load i32, i32* [[A]],
278 // OMP50-NEXT: [[COND:%.+]] = icmp ne i32 [[A_VAL]], 0
279 // OMP50-NEXT: br i1 [[COND]], label {{%?}}[[THEN:[^,]+]], label {{%?}}[[ELSE:[^,]+]]
280 // OMP50:      [[THEN]]:
281 
282 // CHECK: br label %[[SIMD_LOOP8_COND:[^,]+]]
283 // CHECK: [[SIMD_LOOP8_COND]]:
284 // CHECK-NEXT: [[IV8:%.+]] = load i64, i64* [[OMP_IV8]]{{.*}}!llvm.access.group
285 // CHECK-NEXT: [[CMP8:%.+]] = icmp slt i64 [[IV8]], 7
286 // CHECK-NEXT: br i1 [[CMP8]], label %[[SIMPLE_LOOP8_BODY:.+]], label %[[SIMPLE_LOOP8_END:[^,]+]]
287   for (long long i = -10; i < 10; i += 3) {
288 // CHECK: [[SIMPLE_LOOP8_BODY]]:
289 // Start of body: calculate i from IV:
290 // CHECK: [[IV8_0:%.+]] = load i64, i64* [[OMP_IV8]]{{.*}}!llvm.access.group
291 // CHECK-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV8_0]], 3
292 // CHECK-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
293 // CHECK-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],{{.+}}!llvm.access.group
294 // CHECK-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]]{{.+}}!llvm.access.group
295 // CHECK: store i32 %{{.+}}, i32* [[R_PRIV]],{{.+}}!llvm.access.group
296     R *= i;
297 // CHECK: [[IV8_2:%.+]] = load i64, i64* [[OMP_IV8]]{{.*}}!llvm.access.group
298 // CHECK-NEXT: [[ADD8_2:%.+]] = add nsw i64 [[IV8_2]], 1
299 // CHECK-NEXT: store i64 [[ADD8_2]], i64* [[OMP_IV8]]{{.*}}!llvm.access.group
300   }
301 // CHECK: [[SIMPLE_LOOP8_END]]:
302 // OMP50: br label {{%?}}[[EXIT:[^,]+]]
303 // OMP50: br label %[[SIMD_LOOP8_COND:[^,]+]]
304 // OMP50: [[SIMD_LOOP8_COND]]:
305 // OMP50-NEXT: [[IV8:%.+]] = load i64, i64* [[OMP_IV8]],{{[^!]*}}
306 // OMP50-NEXT: [[CMP8:%.+]] = icmp slt i64 [[IV8]], 7
307 // OMP50-NEXT: br i1 [[CMP8]], label %[[SIMPLE_LOOP8_BODY:.+]], label %[[SIMPLE_LOOP8_END:[^,]+]]
308 // OMP50: [[SIMPLE_LOOP8_BODY]]:
309 // Start of body: calculate i from IV:
310 // OMP50: [[IV8_0:%.+]] = load i64, i64* [[OMP_IV8]],{{[^!]*}}
311 // OMP50-NEXT: [[LC_IT_1:%.+]] = mul nsw i64 [[IV8_0]], 3
312 // OMP50-NEXT: [[LC_IT_2:%.+]] = add nsw i64 -10, [[LC_IT_1]]
313 // OMP50-NEXT: store i64 [[LC_IT_2]], i64* [[LC:%[^,]+]],{{[^!]*}}
314 // OMP50-NEXT: [[LC_VAL:%.+]] = load i64, i64* [[LC]],{{[^!]*}}
315 // OMP50: store i32 %{{.+}}, i32* [[R_PRIV]],{{[^!]*}}
316 // OMP50: [[IV8_2:%.+]] = load i64, i64* [[OMP_IV8]],{{[^!]*}}
317 // OMP50-NEXT: [[ADD8_2:%.+]] = add nsw i64 [[IV8_2]], 1
318 // OMP50-NEXT: store i64 [[ADD8_2]], i64* [[OMP_IV8]],{{[^!]*}}
319 // OMP50:      br label {{%?}}[[SIMD_LOOP8_COND]], {{.*}}!llvm.loop ![[DISABLE_VECT:.+]]
320 // OMP50: [[SIMPLE_LOOP8_END]]:
321 // OMP50: br label {{%?}}[[EXIT]]
322 // OMP50: [[EXIT]]:
323 
324 // CHECK-DAG: [[R_VAL:%.+]] = load i32, i32* [[R]],
325 // CHECK-DAG: [[R_PRIV_VAL:%.+]] = load i32, i32* [[R_PRIV]],
326 // CHECK: [[RED:%.+]] = mul nsw i32 [[R_VAL]], [[R_PRIV_VAL]]
327 // CHECK-NEXT: store i32 [[RED]], i32* [[R]],
328 // CHECK-NEXT: ret void
329 }
330 
331 template <class T, unsigned K> T tfoo(T a) { return a + K; }
332 
333 template <typename T, unsigned N>
templ1(T a,T * z)334 int templ1(T a, T *z) {
335   #pragma omp simd collapse(N)
336   for (int i = 0; i < N * 2; i++) {
337     for (long long j = 0; j < (N + N + N + N); j += 2) {
338       z[i + j] = a + tfoo<T, N>(i + j);
339     }
340   }
341   return 0;
342 }
343 
344 // Instatiation templ1<float,2>
345 // CHECK-LABEL: define {{.*i32}} @{{.*}}templ1{{.*}}(float {{.+}}, float* {{.+}})
346 // CHECK: store i64 0, i64* [[T1_OMP_IV:[^,]+]]
347 // ...
348 // CHECK: [[IV:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
349 // CHECK-NEXT: [[CMP1:%.+]] = icmp slt i64 [[IV]], 16
350 // CHECK-NEXT: br i1 [[CMP1]], label %[[T1_BODY:.+]], label %[[T1_END:[^,]+]]
351 // CHECK: [[T1_BODY]]:
352 // Loop counters i and j updates:
353 // CHECK: [[IV1:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
354 // CHECK-NEXT: [[I_1:%.+]] = sdiv i64 [[IV1]], 4
355 // CHECK-NEXT: [[I_1_MUL1:%.+]] = mul nsw i64 [[I_1]], 1
356 // CHECK-NEXT: [[I_1_ADD0:%.+]] = add nsw i64 0, [[I_1_MUL1]]
357 // CHECK-NEXT: [[I_2:%.+]] = trunc i64 [[I_1_ADD0]] to i32
358 // CHECK-NEXT: store i32 [[I_2]], i32* {{%.+}}{{.*}}!llvm.access.group
359 // CHECK: [[IV2:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
360 // CHECK: [[IV2_1:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
361 // CHECK-NEXT: [[J_1_DIV1:%.+]] = sdiv i64 [[IV2_1]], 4
362 // CHECK-NEXT: [[J_1_MUL1:%.+]] = mul nsw i64 [[J_1_DIV1]], 4
363 // CHECK-NEXT: [[J_1_SUB0:%.+]] = sub nsw i64 [[IV2]], [[J_1_MUL1]]
364 // CHECK-NEXT: [[J_2:%.+]] = mul nsw i64 [[J_1_SUB0]], 2
365 // CHECK-NEXT: [[J_2_ADD0:%.+]] = add nsw i64 0, [[J_2]]
366 // CHECK-NEXT: store i64 [[J_2_ADD0]], i64* {{%.+}}{{.*}}!llvm.access.group
367 // simd.for.inc:
368 // CHECK: [[IV3:%.+]] = load i64, i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
369 // CHECK-NEXT: [[INC:%.+]] = add nsw i64 [[IV3]], 1
370 // CHECK-NEXT: store i64 [[INC]], i64* [[T1_OMP_IV]]{{.*}}!llvm.access.group
371 // CHECK-NEXT: br label {{%.+}}
372 // CHECK: [[T1_END]]:
373 // CHECK: ret i32 0
374 //
inst_templ1()375 void inst_templ1() {
376   float a;
377   float z[100];
378   templ1<float,2> (a, z);
379 }
380 
381 
382 typedef int MyIdx;
383 
384 class IterDouble {
385   double *Ptr;
386 public:
operator ++() const387   IterDouble operator++ () const {
388     IterDouble n;
389     n.Ptr = Ptr + 1;
390     return n;
391   }
operator <(const IterDouble & that) const392   bool operator < (const IterDouble &that) const {
393     return Ptr < that.Ptr;
394   }
operator *() const395   double & operator *() const {
396     return *Ptr;
397   }
operator -(const IterDouble & that) const398   MyIdx operator - (const IterDouble &that) const {
399     return (MyIdx) (Ptr - that.Ptr);
400   }
operator +(int Delta)401   IterDouble operator + (int Delta) {
402     IterDouble re;
403     re.Ptr = Ptr + Delta;
404     return re;
405   }
406 
407   ///~IterDouble() {}
408 };
409 
410 // CHECK-LABEL: define {{.*void}} @{{.*}}iter_simple{{.*}}
iter_simple(IterDouble ia,IterDouble ib,IterDouble ic)411 void iter_simple(IterDouble ia, IterDouble ib, IterDouble ic) {
412 //
413 // Calculate number of iterations before the loop body.
414 // CHECK: [[DIFF1:%.+]] = invoke {{.*}}i32 @{{.*}}IterDouble{{.*}}
415 // CHECK: [[DIFF2:%.+]] = sub nsw i32 [[DIFF1]], 1
416 // CHECK-NEXT: [[DIFF3:%.+]] = add nsw i32 [[DIFF2]], 1
417 // CHECK-NEXT: [[DIFF4:%.+]] = sdiv i32 [[DIFF3]], 1
418 // CHECK-NEXT: [[DIFF5:%.+]] = sub nsw i32 [[DIFF4]], 1
419 // CHECK-NEXT: store i32 [[DIFF5]], i32* [[OMP_LAST_IT:%[^,]+]]{{.+}}
420 // CHECK: store i32 0, i32* [[IT_OMP_IV:%[^,]+]]
421   #pragma omp simd
422 
423 // CHECK: [[IV:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}} !llvm.access.group
424 // CHECK-NEXT: [[LAST_IT:%.+]] = load i32, i32* [[OMP_LAST_IT]]{{.+}}!llvm.access.group
425 // CHECK-NEXT: [[NUM_IT:%.+]] = add nsw i32 [[LAST_IT]], 1
426 // CHECK-NEXT: [[CMP:%.+]] = icmp slt i32 [[IV]], [[NUM_IT]]
427 // CHECK-NEXT: br i1 [[CMP]], label %[[IT_BODY:[^,]+]], label %[[IT_END:[^,]+]]
428   for (IterDouble i = ia; i < ib; ++i) {
429 // CHECK: [[IT_BODY]]:
430 // Start of body: calculate i from index:
431 // CHECK: [[IV1:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}}!llvm.access.group
432 // Call of operator+ (i, IV).
433 // CHECK: {{%.+}} = invoke {{.+}} @{{.*}}IterDouble{{.*}}
434 // ... loop body ...
435    *i = *ic * 0.5;
436 // Float multiply and save result.
437 // CHECK: [[MULR:%.+]] = fmul double {{%.+}}, 5.000000e-01
438 // CHECK-NEXT: invoke {{.+}} @{{.*}}IterDouble{{.*}}
439 // CHECK: store double [[MULR:%.+]], double* [[RESULT_ADDR:%.+]], !llvm.access.group
440    ++ic;
441 //
442 // CHECK: [[IV2:%.+]] = load i32, i32* [[IT_OMP_IV]]{{.+}}!llvm.access.group
443 // CHECK-NEXT: [[ADD2:%.+]] = add nsw i32 [[IV2]], 1
444 // CHECK-NEXT: store i32 [[ADD2]], i32* [[IT_OMP_IV]]{{.+}}!llvm.access.group
445 // br label %{{.*}}, !llvm.loop ![[ITER_LOOP_ID]]
446   }
447 // CHECK: [[IT_END]]:
448 // CHECK: ret void
449 }
450 
451 
452 // CHECK-LABEL: define {{.*void}} @{{.*}}collapsed{{.*}}
collapsed(float * a,float * b,float * c,float * d)453 void collapsed(float *a, float *b, float *c, float *d) {
454   int i; // outer loop counter
455   unsigned j; // middle loop couter, leads to unsigned icmp in loop header.
456   // k declared in the loop init below
457   short l; // inner loop counter
458 // CHECK: store i32 0, i32* [[OMP_IV:[^,]+]]
459 //
460   #pragma omp simd collapse(4)
461 
462 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
463 // CHECK-NEXT: [[CMP:%.+]] = icmp ult i32 [[IV]], 120
464 // CHECK-NEXT: br i1 [[CMP]], label %[[COLL1_BODY:[^,]+]], label %[[COLL1_END:[^,]+]]
465   for (i = 1; i < 3; i++) // 2 iterations
466     for (j = 2u; j < 5u; j++) //3 iterations
467       for (int k = 3; k <= 6; k++) // 4 iterations
468         for (l = 4; l < 9; ++l) // 5 iterations
469         {
470 // CHECK: [[COLL1_BODY]]:
471 // Start of body: calculate i from index:
472 // CHECK: [[IV1:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
473 // Calculation of the loop counters values.
474 // CHECK: [[CALC_I_1:%.+]] = udiv i32 [[IV1]], 60
475 // CHECK-NEXT: [[CALC_I_1_MUL1:%.+]] = mul i32 [[CALC_I_1]], 1
476 // CHECK-NEXT: [[CALC_I_2:%.+]] = add i32 1, [[CALC_I_1_MUL1]]
477 // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
478 
479 // CHECK: [[IV1_2:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
480 // CHECK: [[IV1_2_1:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
481 // CHECK-NEXT: [[CALC_J_1:%.+]] = udiv i32 [[IV1_2_1]], 60
482 // CHECK-NEXT: [[MUL_1:%.+]] = mul i32 [[CALC_J_1]], 60
483 // CHECK-NEXT: [[SUB_3:%.+]] = sub i32 [[IV1_2]], [[MUL_1]]
484 // CHECK-NEXT: [[CALC_J_2:%.+]] = udiv i32 [[SUB_3]], 20
485 // CHECK-NEXT: [[CALC_J_2_MUL1:%.+]] = mul i32 [[CALC_J_2]], 1
486 // CHECK-NEXT: [[CALC_J_3:%.+]] = add i32 2, [[CALC_J_2_MUL1]]
487 // CHECK-NEXT: store i32 [[CALC_J_3]], i32* [[LC_J:.+]]
488 
489 // CHECK: [[IV1_3:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
490 // CHECK: [[IV1_3_1:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
491 // CHECK-NEXT: [[DIV_1:%.+]] = udiv i32 [[IV1_3_1]], 60
492 // CHECK-NEXT: [[MUL_2:%.+]] = mul i32 [[DIV_1]], 60
493 // CHECK-NEXT: [[ADD_3:%.+]] = sub i32 [[IV1_3]], [[MUL_2]]
494 
495 // CHECK: [[IV1_4:%.+]] = load i32, i32* [[OMP_IV]]
496 // CHECK: [[IV1_4_1:%.+]] = load i32, i32* [[OMP_IV]]
497 // CHECK-NEXT: [[DIV_2:%.+]] = udiv i32 [[IV1_4_1]], 60
498 // CHECK-NEXT: [[MUL_3:%.+]] = mul i32 [[DIV_2]], 60
499 // CHECK-NEXT: [[SUB_6:%.+]] = sub i32 [[IV1_4]], [[MUL_3]]
500 // CHECK-NEXT: [[DIV_3:%.+]] = udiv i32 [[SUB_6]], 20
501 // CHECK-NEXT: [[MUL_4:%.+]] = mul i32 [[DIV_3]], 20
502 // CHECK-NEXT: [[ADD_5:%.+]] = sub i32 [[ADD_3]], [[MUL_4]]
503 // CHECK-NEXT: [[DIV_4:%.+]] = udiv i32 [[ADD_5]], 5
504 // CHECK-NEXT: [[MUL_5:%.+]] = mul i32 [[DIV_4]], 1
505 // CHECK-NEXT: [[ADD_6:%.+]] = add i32 3, [[MUL_5]]
506 // CHECK-NEXT: store i32 [[ADD_6]], i32* [[LC_K:.+]]
507 
508 // CHECK: [[IV1_5:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
509 // CHECK: [[IV1_5_1:%.+]] = load i32, i32* [[OMP_IV]]{{.+}}!llvm.access.group
510 // CHECK-NEXT: [[DIV_5:%.+]] = udiv i32 [[IV1_5_1]], 60
511 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[DIV_5]], 60
512 // CHECK-NEXT: [[SUB_7:%.+]] = sub i32 [[IV1_5]], [[MUL_6]]
513 
514 // CHECK: [[IV1_6:%.+]] = load i32, i32* [[OMP_IV]]
515 // CHECK: [[IV1_6_1:%.+]] = load i32, i32* [[OMP_IV]]
516 // CHECK-NEXT: [[DIV_6:%.+]] = udiv i32 [[IV1_6_1]], 60
517 // CHECK-NEXT: [[MUL_7:%.+]] = mul i32 [[DIV_6]], 60
518 // CHECK-NEXT: [[SUB_10:%.+]] = sub i32 [[IV1_6]], [[MUL_7]]
519 // CHECK-NEXT: [[DIV_7:%.+]] = udiv i32 [[SUB_10]], 20
520 // CHECK-NEXT: [[MUL_8:%.+]] = mul i32 [[DIV_7]], 20
521 // CHECK-NEXT: [[SUB_11:%.+]] = sub i32 [[SUB_7]], [[MUL_8]]
522 
523 // CHECK: [[IV1_7:%.+]] = load i32, i32* [[OMP_IV]]
524 // CHECK: [[IV1_7_1:%.+]] = load i32, i32* [[OMP_IV]]
525 // CHECK-NEXT: [[DIV_8:%.+]] = udiv i32 [[IV1_7_1]], 60
526 // CHECK-NEXT: [[MUL_9:%.+]] = mul i32 [[DIV_8]], 60
527 // CHECK-NEXT: [[SUB_12:%.+]] = sub i32 [[IV1_7]], [[MUL_9]]
528 
529 // CHECK: [[IV1_8:%.+]] = load i32, i32* [[OMP_IV]]
530 // CHECK: [[IV1_8_1:%.+]] = load i32, i32* [[OMP_IV]]
531 // CHECK-NEXT: [[DIV_3:%.+]] = udiv i32 [[IV1_8_1]], 60
532 // CHECK-NEXT: [[MUL_4:%.+]] = mul i32 [[DIV_3]], 60
533 // CHECK-NEXT: [[SUB_7:%.+]] = sub i32 [[IV1_8]], [[MUL_4]]
534 // CHECK-NEXT: [[DIV_4:%.+]] = udiv i32 [[SUB_7]], 20
535 // CHECK-NEXT: [[MUL_5:%.+]] = mul i32 [[DIV_4]], 20
536 // CHECK-NEXT: [[SUB_8:%.+]] = sub i32 [[SUB_12]], [[MUL_5]]
537 // CHECK-NEXT: [[DIV_5:%.+]] = udiv i32 [[SUB_8]], 5
538 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[DIV_5]], 5
539 // CHECK-NEXT: [[SUB_9:%.+]] = sub i32 [[SUB_11]], [[MUL_6]]
540 // CHECK-NEXT: [[MUL_6:%.+]] = mul i32 [[SUB_9]], 1
541 // CHECK-NEXT: [[CALC_L_2:%.+]] = add i32 4, [[MUL_6]]
542 // CHECK-NEXT: [[CALC_L_3:%.+]] = trunc i32 [[CALC_L_2]] to i16
543 // CHECK-NEXT: store i16 [[CALC_L_3]], i16* [[LC_L:.+]]
544 // ... loop body ...
545 // End of body: store into a[i]:
546 // CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]{{.+}}!llvm.access.group
547     float res = b[j] * c[k];
548     a[i] = res * d[l];
549 // CHECK: [[IV2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
550 // CHECK-NEXT: [[ADD2:%.+]] = add i32 [[IV2]], 1
551 // CHECK-NEXT: store i32 [[ADD2]], i32* [[OMP_IV]]{{.*}}!llvm.access.group
552 // br label %{{[^,]+}}, !llvm.loop ![[COLL1_LOOP_ID]]
553 // CHECK: [[COLL1_END]]:
554   }
555 // i,j,l are updated; k is not updated.
556 // CHECK: store i32 3, i32*
557 // CHECK-NEXT: store i32 5, i32*
558 // CHECK-NEXT: store i32 7, i32*
559 // CHECK-NEXT: store i16 9, i16*
560 // CHECK: ret void
561 }
562 
563 extern char foo();
564 extern double globalfloat;
565 
566 // CHECK-LABEL: define {{.*void}} @{{.*}}widened{{.*}}
widened(float * a,float * b,float * c,float * d)567 void widened(float *a, float *b, float *c, float *d) {
568   int i; // outer loop counter
569   short j; // inner loop counter
570   globalfloat = 1.0;
571   int localint = 1;
572 // CHECK: store double {{.+}}, double* [[GLOBALFLOAT:@.+]]
573 // Counter is widened to 64 bits.
574 // CHECK: store i64 0, i64* [[OMP_IV:[^,]+]]
575 //
576   #pragma omp simd collapse(2) private(globalfloat, localint)
577 
578 // CHECK: [[IV:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.access.group
579 // CHECK-NEXT: [[LI:%.+]] = load i64, i64* [[OMP_LI:%[^,]+]]{{.+}}!llvm.access.group
580 // CHECK-NEXT: [[NUMIT:%.+]] = add nsw i64 [[LI]], 1
581 // CHECK-NEXT: [[CMP:%.+]] = icmp slt i64 [[IV]], [[NUMIT]]
582 // CHECK-NEXT: br i1 [[CMP]], label %[[WIDE1_BODY:[^,]+]], label %[[WIDE1_END:[^,]+]]
583   for (i = 1; i < 3; i++) // 2 iterations
584     for (j = 0; j < foo(); j++) // foo() iterations
585   {
586 // CHECK: [[WIDE1_BODY]]:
587 // Start of body: calculate i from index:
588 // CHECK: [[IV1:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.access.group
589 // Calculation of the loop counters values...
590 // CHECK: store i32 {{[^,]+}}, i32* [[LC_I:.+]]
591 // CHECK: [[IV1_2:%.+]] = load i64, i64* [[OMP_IV]]{{.+}}!llvm.access.group
592 // CHECK: store i16 {{[^,]+}}, i16* [[LC_J:.+]]
593 // ... loop body ...
594 //
595 // Here we expect store into private double var, not global
596 // CHECK-NOT: store double {{.+}}, double* [[GLOBALFLOAT]]
597     globalfloat = (float)j/i;
598     float res = b[j] * c[j];
599 // Store into a[i]:
600 // CHECK: store float [[RESULT:%.+]], float* [[RESULT_ADDR:%.+]]{{.+}}!llvm.access.group
601     a[i] = res * d[i];
602 // Then there's a store into private var localint:
603 // CHECK: store i32 {{.+}}, i32* [[LOCALINT:%[^,]+]]{{.+}}!llvm.access.group
604     localint = (int)j;
605 // CHECK: [[IV2:%.+]] = load i64, i64* [[OMP_IV]]{{.*}}!llvm.access.group
606 // CHECK-NEXT: [[ADD2:%.+]] = add nsw i64 [[IV2]], 1
607 // CHECK-NEXT: store i64 [[ADD2]], i64* [[OMP_IV]]{{.*}}!llvm.access.group
608 //
609 // br label %{{[^,]+}}, !llvm.loop ![[WIDE1_LOOP_ID]]
610 // CHECK: [[WIDE1_END]]:
611   }
612 // i,j are updated.
613 // CHECK: store i32 3, i32* [[I:%[^,]+]]
614 // CHECK: store i16
615 //
616 // Here we expect store into original localint, not its privatized version.
617 // CHECK-NOT: store i32 {{.+}}, i32* [[LOCALINT]]
618   localint = (int)j;
619 // CHECK: ret void
620 }
621 
622 // CHECK-LABEL: define {{.*void}} @{{.*}}linear{{.*}}(float* {{.+}})
linear(float * a)623 void linear(float *a) {
624   // CHECK: [[VAL_ADDR:%.+]] = alloca i64,
625   // CHECK: [[K_ADDR:%.+]] = alloca i64*,
626   long long val = 0;
627   long long &k = val;
628 
629   #pragma omp simd linear(k : 3)
630 // CHECK: store i64* [[VAL_ADDR]], i64** [[K_ADDR]],
631 // CHECK: [[VAL_REF:%.+]] = load i64*, i64** [[K_ADDR]],
632 // CHECK: store i64* [[VAL_REF]], i64** [[K_ADDR_REF:%.+]],
633 // CHECK: store i32 0, i32* [[OMP_IV:%[^,]+]]
634 // CHECK: [[K_REF:%.+]] = load i64*, i64** [[K_ADDR_REF]],
635 // CHECK: [[K0LOAD:%.+]] = load i64, i64* [[K_REF]]
636 // CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
637 
638 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
639 // CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV]], 9
640 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP_BODY:.+]], label %[[SIMPLE_LOOP_END:[^,]+]]
641   for (int i = 10; i > 1; i--) {
642 // CHECK: [[SIMPLE_LOOP_BODY]]:
643 // Start of body: calculate i from IV:
644 // CHECK: [[IV_0:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
645 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
646 // CHECK-NEXT: [[IV_1:%.+]] = mul nsw i32 [[IV_0]], 1
647 // CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV_1]]
648 // CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.access.group
649 //
650 // CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.access.group
651 // CHECK-NEXT: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
652 // CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV_2]], 3
653 // CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
654 // CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
655 // Update of the privatized version of linear variable!
656 // CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
657     a[k]++;
658     k = k + 3;
659 // CHECK: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
660 // CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV_2]], 1
661 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV]]{{.*}}!llvm.access.group
662 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP_ID]]
663   }
664 // CHECK: [[SIMPLE_LOOP_END]]:
665 //
666 // Update linear vars after loop, as the loop was operating on a private version.
667 // CHECK: [[K_REF:%.+]] = load i64*, i64** [[K_ADDR_REF]],
668 // CHECK: store i64* [[K_REF]], i64** [[K_PRIV_REF:%.+]],
669 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
670 // CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
671 // CHECK-NEXT: [[K_REF:%.+]] = load i64*, i64** [[K_PRIV_REF]],
672 // CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[K_REF]]
673 //
674 
675   #pragma omp simd linear(val(k) : 3)
676 // CHECK: [[VAL_REF:%.+]] = load i64*, i64** [[K_ADDR]],
677 // CHECK: store i64* [[VAL_REF]], i64** [[K_ADDR_REF:%.+]],
678 // CHECK: store i32 0, i32* [[OMP_IV:%[^,]+]]
679 // CHECK: [[K_REF:%.+]] = load i64*, i64** [[K_ADDR_REF]],
680 // CHECK: [[K0LOAD:%.+]] = load i64, i64* [[K_REF]]
681 // CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
682 
683 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
684 // CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV]], 9
685 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP_BODY:.+]], label %[[SIMPLE_LOOP_END:[^,]+]]
686   for (int i = 10; i > 1; i--) {
687 // CHECK: [[SIMPLE_LOOP_BODY]]:
688 // Start of body: calculate i from IV:
689 // CHECK: [[IV_0:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
690 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
691 // CHECK-NEXT: [[IV_1:%.+]] = mul nsw i32 [[IV_0]], 1
692 // CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV_1]]
693 // CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.access.group
694 //
695 // CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.access.group
696 // CHECK-NEXT: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
697 // CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV_2]], 3
698 // CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
699 // CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
700 // Update of the privatized version of linear variable!
701 // CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
702     a[k]++;
703     k = k + 3;
704 // CHECK: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
705 // CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV_2]], 1
706 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV]]{{.*}}!llvm.access.group
707 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP_ID]]
708   }
709 // CHECK: [[SIMPLE_LOOP_END]]:
710 //
711 // Update linear vars after loop, as the loop was operating on a private version.
712 // CHECK: [[K_REF:%.+]] = load i64*, i64** [[K_ADDR_REF]],
713 // CHECK: store i64* [[K_REF]], i64** [[K_PRIV_REF:%.+]],
714 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
715 // CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
716 // CHECK-NEXT: [[K_REF:%.+]] = load i64*, i64** [[K_PRIV_REF]],
717 // CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[K_REF]]
718 //
719   #pragma omp simd linear(uval(k) : 3)
720 // CHECK: store i32 0, i32* [[OMP_IV:%[^,]+]]
721 // CHECK: [[K0LOAD:%.+]] = load i64, i64* [[VAL_ADDR]]
722 // CHECK-NEXT: store i64 [[K0LOAD]], i64* [[LIN0:%[^,]+]]
723 
724 // CHECK: [[IV:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
725 // CHECK-NEXT: [[CMP2:%.+]] = icmp slt i32 [[IV]], 9
726 // CHECK-NEXT: br i1 [[CMP2]], label %[[SIMPLE_LOOP_BODY:.+]], label %[[SIMPLE_LOOP_END:[^,]+]]
727   for (int i = 10; i > 1; i--) {
728 // CHECK: [[SIMPLE_LOOP_BODY]]:
729 // Start of body: calculate i from IV:
730 // CHECK: [[IV_0:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
731 // FIXME: It is interesting, why the following "mul 1" was not constant folded?
732 // CHECK-NEXT: [[IV_1:%.+]] = mul nsw i32 [[IV_0]], 1
733 // CHECK-NEXT: [[LC_I_1:%.+]] = sub nsw i32 10, [[IV_1]]
734 // CHECK-NEXT: store i32 [[LC_I_1]], i32* {{.+}}, !llvm.access.group
735 //
736 // CHECK-NEXT: [[LIN0_1:%.+]] = load i64, i64* [[LIN0]]{{.*}}!llvm.access.group
737 // CHECK-NEXT: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
738 // CHECK-NEXT: [[LIN_MUL1:%.+]] = mul nsw i32 [[IV_2]], 3
739 // CHECK-NEXT: [[LIN_EXT1:%.+]] = sext i32 [[LIN_MUL1]] to i64
740 // CHECK-NEXT: [[LIN_ADD1:%.+]] = add nsw i64 [[LIN0_1]], [[LIN_EXT1]]
741 // Update of the privatized version of linear variable!
742 // CHECK-NEXT: store i64 [[LIN_ADD1]], i64* [[K_PRIVATIZED:%[^,]+]]
743     a[k]++;
744     k = k + 3;
745 // CHECK: [[IV_2:%.+]] = load i32, i32* [[OMP_IV]]{{.*}}!llvm.access.group
746 // CHECK-NEXT: [[ADD2_2:%.+]] = add nsw i32 [[IV_2]], 1
747 // CHECK-NEXT: store i32 [[ADD2_2]], i32* [[OMP_IV]]{{.*}}!llvm.access.group
748 // br label {{.+}}, !llvm.loop ![[SIMPLE_LOOP_ID]]
749   }
750 // CHECK: [[SIMPLE_LOOP_END]]:
751 //
752 // Update linear vars after loop, as the loop was operating on a private version.
753 // CHECK: [[LIN0_2:%.+]] = load i64, i64* [[LIN0]]
754 // CHECK-NEXT: [[LIN_ADD2:%.+]] = add nsw i64 [[LIN0_2]], 27
755 // CHECK-NEXT: store i64 [[LIN_ADD2]], i64* [[VAL_ADDR]]
756 //
757 }
758 
759 #ifdef OMP5
760 // OMP50-LABEL: inner_simd
inner_simd()761 void inner_simd() {
762   double a, b;
763 #pragma omp simd nontemporal(a)
764   for (int i = 0; i < 10; ++i) {
765 #pragma omp simd nontemporal(b)
766     for (int k = 0; k < 10; ++k) {
767       // OMP50: load double,{{.*}}!nontemporal
768       // OMP50: store double{{.*}}!nontemporal
769       a = b;
770     }
771     // OMP50-NOT: load double,{{.*}}!nontemporal
772     // OMP50: load double,
773     // OMP50: store double{{.*}}!nontemporal
774     a = b;
775   }
776 }
777 
778 extern struct T t;
779 struct Base {
780   float a;
781 };
782 struct T : public Base {
fooT783   void foo() {
784 #pragma omp simd nontemporal(Base::a)
785     for (int i = 0; i < 10; ++i) {
786     // OMP50: store float{{.*}}!nontemporal
787     // OMP50-NOT: nontemporal
788     // OMP50-NEXT: store float
789       Base::a = 0;
790       t.a = 0;
791     }
792   }
793 } t;
794 
bartfoo()795 void bartfoo() {
796   t.foo();
797 }
798 
799 #endif // OMP5
800 // TERM_DEBUG-LABEL: bar
bar()801 int bar() { extern void mayThrow(); mayThrow(); return 0; };
802 
803 // TERM_DEBUG-LABEL: parallel_simd
parallel_simd(float * a)804 void parallel_simd(float *a) {
805 #pragma omp parallel
806 #pragma omp simd
807   // TERM_DEBUG-NOT: __kmpc_global_thread_num
808   // TERM_DEBUG:     invoke i32 {{.*}}bar{{.*}}()
809   // TERM_DEBUG:     unwind label %[[TERM_LPAD:[^,]+]],
810   // TERM_DEBUG-NOT: __kmpc_global_thread_num
811   // TERM_DEBUG:     [[TERM_LPAD]]
812   // TERM_DEBUG:     call void @__clang_call_terminate
813   // TERM_DEBUG:     unreachable
814   for (unsigned i = 131071; i <= 2147483647; i += 127)
815     a[i] += bar();
816 }
817 // TERM_DEBUG: !{{[0-9]+}} = !DILocation(line: [[@LINE-11]],
818 
819 // CHECK-LABEL: S8
820 // CHECK-DAG: call void @llvm.assume(i1
821 // CHECK-DAG: call void @llvm.assume(i1
822 // CHECK-DAG: call void @llvm.assume(i1
823 // CHECK-DAG: call void @llvm.assume(i1
824 struct SS {
SSSS825   SS(): a(0) {}
SSSS826   SS(int v) : a(v) {}
827   int a;
828   typedef int type;
829 };
830 
831 template <typename T>
832 class S7 : public T {
833 protected:
834   T *a;
835   T b[2];
S7()836   S7() : a(0) {}
837 
838 public:
S7(typename T::type & v)839   S7(typename T::type &v) : a((T*)&v) {
840 #pragma omp simd aligned(a)
841     for (int k = 0; k < a->a; ++k)
842       ++this->a->a;
843 #pragma omp simd aligned(this->b : 8)
844     for (int k = 0; k < a->a; ++k)
845       ++a->a;
846   }
847 };
848 
849 class S8 : private IterDouble, public S7<SS> {
S8()850   S8() {}
851 
852 public:
S8(int v)853   S8(int v) : S7<SS>(v){
854 #pragma omp parallel private(a)
855 #pragma omp simd aligned(S7<SS>::a)
856     for (int k = 0; k < a->a; ++k)
857       ++this->a->a;
858 #pragma omp parallel shared(b)
859 #pragma omp simd aligned(this->b: 4)
860     for (int k = 0; k < a->a; ++k)
861       ++a->a;
862   }
863 };
864 S8 s8(0);
865 
866 // TERM_DEBUG-NOT: line: 0,
867 // TERM_DEBUG: distinct !DISubprogram(linkageName: "_GLOBAL__sub_I_simd_codegen.cpp",
868 // OMP50-DAG: ![[NOVECT:.+]] = !{!"llvm.loop.vectorize.enable", i1 false}
869 // OMP50-DAG: ![[DISABLE_VECT]] = distinct !{{.*}}![[NOVECT]]{{[,}]}}
870 #endif // HEADER
871 
872