xref: /minix3/external/bsd/llvm/dist/clang/test/OpenMP/for_codegen.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -verify -fopenmp=libiomp5 -x c++ -emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -fopenmp=libiomp5 -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -g -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s
4*0a6a1f1dSLionel Sambuc //
5*0a6a1f1dSLionel Sambuc // expected-no-diagnostics
6*0a6a1f1dSLionel Sambuc #ifndef HEADER
7*0a6a1f1dSLionel Sambuc #define HEADER
8*0a6a1f1dSLionel Sambuc 
9*0a6a1f1dSLionel Sambuc // CHECK: [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, i8* }
10*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*void}} @{{.*}}without_schedule_clause{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
without_schedule_clause(float * a,float * b,float * c,float * d)11*0a6a1f1dSLionel Sambuc void without_schedule_clause(float *a, float *b, float *c, float *d) {
12*0a6a1f1dSLionel Sambuc // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
13*0a6a1f1dSLionel Sambuc   #pragma omp for
14*0a6a1f1dSLionel Sambuc // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1)
15*0a6a1f1dSLionel Sambuc // UB = min(UB, GlobalUB)
16*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UB:%.+]] = load i32* [[OMP_UB]]
17*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423
18*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]]
19*0a6a1f1dSLionel Sambuc // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ]
20*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]]
21*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[LB:%.+]] = load i32* [[OMP_LB]]
22*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
23*0a6a1f1dSLionel Sambuc // Loop header
24*0a6a1f1dSLionel Sambuc // CHECK: [[IV:%.+]] = load i32* [[OMP_IV]]
25*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UB:%.+]] = load i32* [[OMP_UB]]
26*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
27*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
28*0a6a1f1dSLionel Sambuc   for (int i = 33; i < 32000000; i += 7) {
29*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP1_BODY]]
30*0a6a1f1dSLionel Sambuc // Start of body: calculate i from IV:
31*0a6a1f1dSLionel Sambuc // CHECK: [[IV1_1:%.+]] = load i32* [[OMP_IV]]
32*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7
33*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALC_I_2:%.+]] = add nsw i32 33, [[CALC_I_1]]
34*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
35*0a6a1f1dSLionel Sambuc // ... loop body ...
36*0a6a1f1dSLionel Sambuc // End of body: store into a[i]:
37*0a6a1f1dSLionel Sambuc // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
38*0a6a1f1dSLionel Sambuc     a[i] = b[i] * c[i] * d[i];
39*0a6a1f1dSLionel Sambuc // CHECK: [[IV1_2:%.+]] = load i32* [[OMP_IV]]{{.*}}
40*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
41*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
42*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br label %{{.+}}
43*0a6a1f1dSLionel Sambuc   }
44*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP1_END]]
45*0a6a1f1dSLionel Sambuc // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
46*0a6a1f1dSLionel Sambuc // CHECK: call {{.+}} @__kmpc_cancel_barrier([[IDENT_T_TY]]* [[DEFAULT_LOC_BARRIER:[@%].+]], i32 [[GTID]])
47*0a6a1f1dSLionel Sambuc // CHECK: ret void
48*0a6a1f1dSLionel Sambuc }
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define {{.*void}} @{{.*}}static_not_chunked{{.*}}(float* {{.+}}, float* {{.+}}, float* {{.+}}, float* {{.+}})
static_not_chunked(float * a,float * b,float * c,float * d)51*0a6a1f1dSLionel Sambuc void static_not_chunked(float *a, float *b, float *c, float *d) {
52*0a6a1f1dSLionel Sambuc // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num([[IDENT_T_TY]]* [[DEFAULT_LOC:[@%].+]])
53*0a6a1f1dSLionel Sambuc   #pragma omp for schedule(static)
54*0a6a1f1dSLionel Sambuc // CHECK: call void @__kmpc_for_static_init_4([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]], i32 34, i32* [[IS_LAST:%[^,]+]], i32* [[OMP_LB:%[^,]+]], i32* [[OMP_UB:%[^,]+]], i32* [[OMP_ST:%[^,]+]], i32 1, i32 1)
55*0a6a1f1dSLionel Sambuc // UB = min(UB, GlobalUB)
56*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UB:%.+]] = load i32* [[OMP_UB]]
57*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UBCMP:%.+]] = icmp sgt i32 [[UB]], 4571423
58*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br i1 [[UBCMP]], label [[UB_TRUE:%[^,]+]], label [[UB_FALSE:%[^,]+]]
59*0a6a1f1dSLionel Sambuc // CHECK: [[UBRESULT:%.+]] = phi i32 [ 4571423, [[UB_TRUE]] ], [ [[UBVAL:%[^,]+]], [[UB_FALSE]] ]
60*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[UBRESULT]], i32* [[OMP_UB]]
61*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[LB:%.+]] = load i32* [[OMP_LB]]
62*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[LB]], i32* [[OMP_IV:[^,]+]]
63*0a6a1f1dSLionel Sambuc // Loop header
64*0a6a1f1dSLionel Sambuc // CHECK: [[IV:%.+]] = load i32* [[OMP_IV]]
65*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[UB:%.+]] = load i32* [[OMP_UB]]
66*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CMP:%.+]] = icmp sle i32 [[IV]], [[UB]]
67*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br i1 [[CMP]], label %[[LOOP1_BODY:[^,]+]], label %[[LOOP1_END:[^,]+]]
68*0a6a1f1dSLionel Sambuc   for (int i = 32000000; i > 33; i += -7) {
69*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP1_BODY]]
70*0a6a1f1dSLionel Sambuc // Start of body: calculate i from IV:
71*0a6a1f1dSLionel Sambuc // CHECK: [[IV1_1:%.+]] = load i32* [[OMP_IV]]
72*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALC_I_1:%.+]] = mul nsw i32 [[IV1_1]], 7
73*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[CALC_I_2:%.+]] = sub nsw i32 32000000, [[CALC_I_1]]
74*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[CALC_I_2]], i32* [[LC_I:.+]]
75*0a6a1f1dSLionel Sambuc // ... loop body ...
76*0a6a1f1dSLionel Sambuc // End of body: store into a[i]:
77*0a6a1f1dSLionel Sambuc // CHECK: store float [[RESULT:%.+]], float* {{%.+}}
78*0a6a1f1dSLionel Sambuc     a[i] = b[i] * c[i] * d[i];
79*0a6a1f1dSLionel Sambuc // CHECK: [[IV1_2:%.+]] = load i32* [[OMP_IV]]{{.*}}
80*0a6a1f1dSLionel Sambuc // CHECK-NEXT: [[ADD1_2:%.+]] = add nsw i32 [[IV1_2]], 1
81*0a6a1f1dSLionel Sambuc // CHECK-NEXT: store i32 [[ADD1_2]], i32* [[OMP_IV]]
82*0a6a1f1dSLionel Sambuc // CHECK-NEXT: br label %{{.+}}
83*0a6a1f1dSLionel Sambuc   }
84*0a6a1f1dSLionel Sambuc // CHECK: [[LOOP1_END]]
85*0a6a1f1dSLionel Sambuc // CHECK: call void @__kmpc_for_static_fini([[IDENT_T_TY]]* [[DEFAULT_LOC]], i32 [[GTID]])
86*0a6a1f1dSLionel Sambuc // CHECK: call {{.+}} @__kmpc_cancel_barrier([[IDENT_T_TY]]* [[DEFAULT_LOC_BARRIER:[@%].+]], i32 [[GTID]])
87*0a6a1f1dSLionel Sambuc // CHECK: ret void
88*0a6a1f1dSLionel Sambuc }
89*0a6a1f1dSLionel Sambuc 
90*0a6a1f1dSLionel Sambuc #endif // HEADER
91*0a6a1f1dSLionel Sambuc 
92