master_taskloop_simd_reduction_codegen.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. // RUN: %clang_cc1 -fopenmp -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -std=c++98 | FileCheck %s
  2. // RUN: %clang_cc1 -fopenmp-simd -x c++ %s -verify -debug-info-kind=limited -emit-llvm -o - -triple powerpc64le-unknown-linux-gnu -std=c++98 | FileCheck --check-prefix SIMD-ONLY0 %s
  3. // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
  4. // expected-no-diagnostics
  5. struct S {
  6. float a;
  7. S() : a(0.0f) {}
  8. ~S() {}
  9. };
  10. #pragma omp declare reduction(+:S:omp_out.a += omp_in.a) initializer(omp_priv = omp_orig)
  11. float g;
  12. int a;
  13. #pragma omp threadprivate(a)
  14. int main (int argc, char *argv[])
  15. {
  16. int i, n;
  17. float a[100], b[100], sum, e[argc + 100];
  18. S c[100];
  19. float &d = g;
  20. /* Some initializations */
  21. n = 100;
  22. for (i=0; i < n; i++)
  23. a[i] = b[i] = i * 1.0;
  24. sum = 0.0;
  25. #pragma omp master taskloop simd reduction(+:sum, c[:n], d, e)
  26. for (i=0; i < n; i++) {
  27. sum = sum + (a[i] * b[i]);
  28. c[i].a = i*i;
  29. d += i*i;
  30. e[i] = i;
  31. }
  32. }
  33. // CHECK-LABEL: @main(
  34. // CHECK: [[RETVAL:%.*]] = alloca i32,
  35. // CHECK: [[ARGC_ADDR:%.*]] = alloca i32,
  36. // CHECK: [[ARGV_ADDR:%.*]] = alloca i8**,
  37. // CHECK: [[I:%.*]] = alloca i32,
  38. // CHECK: [[N:%.*]] = alloca i32,
  39. // CHECK: [[A:%.*]] = alloca [100 x float],
  40. // CHECK: [[B:%.*]] = alloca [100 x float],
  41. // CHECK: [[SUM:%.*]] = alloca float,
  42. // CHECK: [[SAVED_STACK:%.*]] = alloca i8*,
  43. // CHECK: [[C:%.*]] = alloca [100 x %struct.S],
  44. // CHECK: [[D:%.*]] = alloca float*,
  45. // CHECK: [[AGG_CAPTURED:%.*]] = alloca [[STRUCT_ANON:%.*]],
  46. // CHECK: [[DOTRD_INPUT_:%.*]] = alloca [4 x %struct.kmp_task_red_input_t],
  47. // CHECK: alloca i32,
  48. // CHECK: [[DOTCAPTURE_EXPR_:%.*]] = alloca i32,
  49. // CHECK: [[DOTCAPTURE_EXPR_9:%.*]] = alloca i32,
  50. // CHECK: [[TMP0:%.*]] = call i32 @__kmpc_global_thread_num(%struct.ident_t*
  51. // CHECK: store i32 0, i32* [[RETVAL]],
  52. // CHECK: store i32 [[ARGC:%.*]], i32* [[ARGC_ADDR]],
  53. // CHECK: store i8** [[ARGV:%.*]], i8*** [[ARGV_ADDR]],
  54. // CHECK: [[TMP1:%.*]] = load i32, i32* [[ARGC_ADDR]],
  55. // CHECK: [[ADD:%.*]] = add nsw i32 [[TMP1]], 100
  56. // CHECK: [[TMP2:%.*]] = zext i32 [[ADD]] to i64
  57. // CHECK: [[VLA:%.+]] = alloca float, i64 %
  58. // CHECK: call void @__kmpc_taskgroup(%struct.ident_t*
  59. // CHECK-DAG: [[TMP21:%.*]] = bitcast float* [[SUM]] to i8*
  60. // CHECK-DAG: store i8* [[TMP21]], i8** [[TMP20:%[^,]+]],
  61. // CHECK-DAG: [[TMP20]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T:%.+]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_:%.+]], i32 0, i32 0
  62. // CHECK-DAG: [[TMP22:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 1
  63. // CHECK-DAG: store i64 4, i64* [[TMP22]],
  64. // CHECK-DAG: [[TMP23:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 2
  65. // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT1:.+]] to i8*), i8** [[TMP23]],
  66. // CHECK-DAG: [[TMP24:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 3
  67. // CHECK-DAG: store i8* null, i8** [[TMP24]],
  68. // CHECK-DAG: [[TMP25:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 4
  69. // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB1:.+]] to i8*), i8** [[TMP25]],
  70. // CHECK-DAG: [[TMP26:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_]], i32 0, i32 5
  71. // CHECK-DAG: [[TMP27:%.*]] = bitcast i32* [[TMP26]] to i8*
  72. // CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP27]], i8 0, i64 4, i1 false)
  73. // CHECK-DAG: [[ARRAYIDX5:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 0
  74. // CHECK-DAG: [[LB_ADD_LEN:%.*]] = add nsw i64 -1, %
  75. // CHECK-DAG: [[ARRAYIDX6:%.*]] = getelementptr inbounds [100 x %struct.S], [100 x %struct.S]* [[C]], i64 0, i64 [[LB_ADD_LEN]]
  76. // CHECK-DAG: [[TMP31:%.*]] = bitcast %struct.S* [[ARRAYIDX5]] to i8*
  77. // CHECK-DAG: store i8* [[TMP31]], i8** [[TMP28:%[^,]+]],
  78. // CHECK-DAG: [[TMP28]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4:%.+]], i32 0, i32 0
  79. // CHECK-DAG: [[TMP32:%.*]] = ptrtoint %struct.S* [[ARRAYIDX6]] to i64
  80. // CHECK-DAG: [[TMP33:%.*]] = ptrtoint %struct.S* [[ARRAYIDX5]] to i64
  81. // CHECK-DAG: [[TMP34:%.*]] = sub i64 [[TMP32]], [[TMP33]]
  82. // CHECK-DAG: [[TMP35:%.*]] = sdiv exact i64 [[TMP34]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
  83. // CHECK-DAG: [[TMP36:%.*]] = add nuw i64 [[TMP35]], 1
  84. // CHECK-DAG: [[TMP37:%.*]] = mul nuw i64 [[TMP36]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
  85. // CHECK-DAG: store i64 [[TMP37]], i64* [[TMP38:%[^,]+]],
  86. // CHECK-DAG: [[TMP38]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 1
  87. // CHECK-DAG: [[TMP39:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 2
  88. // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT2:.+]] to i8*), i8** [[TMP39]],
  89. // CHECK-DAG: [[TMP40:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 3
  90. // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_FINI2:.+]] to i8*), i8** [[TMP40]],
  91. // CHECK-DAG: [[TMP41:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 4
  92. // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB2:.+]] to i8*), i8** [[TMP41]],
  93. // CHECK-DAG: [[TMP42:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_4]], i32 0, i32 5
  94. // CHECK-DAG: store i32 1, i32* [[TMP42]],
  95. // CHECK-DAG: [[TMP44:%.*]] = load float*, float** [[D]],
  96. // CHECK-DAG: [[TMP45:%.*]] = bitcast float* [[TMP44]] to i8*
  97. // CHECK-DAG: store i8* [[TMP45]], i8** [[TMP43:%[^,]+]],
  98. // CHECK-DAG: [[TMP43]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7:%.+]], i32 0, i32 0
  99. // CHECK-DAG: [[TMP46:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 1
  100. // CHECK-DAG: store i64 4, i64* [[TMP46]],
  101. // CHECK-DAG: [[TMP47:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 2
  102. // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT3:.+]] to i8*), i8** [[TMP47]],
  103. // CHECK-DAG: [[TMP48:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 3
  104. // CHECK-DAG: store i8* null, i8** [[TMP48]],
  105. // CHECK-DAG: [[TMP49:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 4
  106. // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB3:.+]] to i8*), i8** [[TMP49]],
  107. // CHECK-DAG: [[TMP50:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_7]], i32 0, i32 5
  108. // CHECK-DAG: [[TMP51:%.*]] = bitcast i32* [[TMP50]] to i8*
  109. // CHECK-DAG: call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP51]], i8 0, i64 4, i1 false)
  110. // CHECK-DAG: [[TMP53:%.*]] = bitcast float* [[VLA]] to i8*
  111. // CHECK-DAG: store i8* [[TMP53]], i8** [[TMP52:%[^,]+]],
  112. // CHECK-DAG: [[TMP52]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8:%.+]], i32 0, i32 0
  113. // CHECK-DAG: [[TMP54:%.*]] = mul nuw i64 [[TMP2]], 4
  114. // CHECK-DAG: [[TMP55:%.*]] = udiv exact i64 [[TMP54]], ptrtoint (float* getelementptr (float, float* null, i32 1) to i64)
  115. // CHECK-DAG: store i64 [[TMP54]], i64* [[TMP56:%[^,]+]],
  116. // CHECK-DAG: [[TMP56]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 1
  117. // CHECK-DAG: [[TMP57:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 2
  118. // CHECK-DAG: store i8* bitcast (void (i8*)* @[[RED_INIT4:.+]] to i8*), i8** [[TMP57]],
  119. // CHECK-DAG: [[TMP58:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 3
  120. // CHECK-DAG: store i8* null, i8** [[TMP58]],
  121. // CHECK-DAG: [[TMP59:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 4
  122. // CHECK-DAG: store i8* bitcast (void (i8*, i8*)* @[[RED_COMB4:.+]] to i8*), i8** [[TMP59]],
  123. // CHECK-DAG: [[TMP60:%.*]] = getelementptr inbounds [[STRUCT_KMP_TASK_RED_INPUT_T]], %struct.kmp_task_red_input_t* [[DOTRD_INPUT_GEP_8]], i32 0, i32 5
  124. // CHECK-DAG: store i32 1, i32* [[TMP60]],
  125. // CHECK-DAG: [[DOTRD_INPUT_GEP_]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
  126. // CHECK-DAG: [[DOTRD_INPUT_GEP_4]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
  127. // CHECK-DAG: [[DOTRD_INPUT_GEP_7]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
  128. // CHECK-DAG: [[DOTRD_INPUT_GEP_8]] = getelementptr inbounds [4 x %struct.kmp_task_red_input_t], [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]], i64 0, i64
  129. // CHECK: [[TMP61:%.*]] = bitcast [4 x %struct.kmp_task_red_input_t]* [[DOTRD_INPUT_]] to i8*
  130. // CHECK: [[TMP62:%.*]] = call i8* @__kmpc_task_reduction_init(i32 [[TMP0]], i32 4, i8* [[TMP61]])
  131. // CHECK: [[TMP63:%.*]] = load i32, i32* [[N]],
  132. // CHECK: store i32 [[TMP63]], i32* [[DOTCAPTURE_EXPR_]],
  133. // CHECK: [[TMP64:%.*]] = load i32, i32* [[DOTCAPTURE_EXPR_]],
  134. // CHECK: [[SUB:%.*]] = sub nsw i32 [[TMP64]], 0
  135. // CHECK: [[SUB10:%.*]] = sub nsw i32 [[SUB]], 1
  136. // CHECK: [[ADD11:%.*]] = add nsw i32 [[SUB10]], 1
  137. // CHECK: [[DIV:%.*]] = sdiv i32 [[ADD11]], 1
  138. // CHECK: [[SUB12:%.*]] = sub nsw i32 [[DIV]], 1
  139. // CHECK: store i32 [[SUB12]], i32* [[DOTCAPTURE_EXPR_9]],
  140. // CHECK: [[TMP65:%.*]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* %{{.+}}, i32 [[TMP0]], i32 1, i64 888, i64 72, i32 (i32, i8*)* bitcast (i32 (i32, %struct.kmp_task_t_with_privates*)* @{{.+}} to i32 (i32, i8*)*))
  141. // CHECK: call void @__kmpc_taskloop(%struct.ident_t* %{{.+}}, i32 [[TMP0]], i8* [[TMP65]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* null)
  142. // CHECK: call void @__kmpc_end_taskgroup(%struct.ident_t*
  143. // CHECK: ret i32
  144. // CHECK: define internal void @[[RED_INIT1]](i8* %0)
  145. // CHECK: store float 0.000000e+00, float* %
  146. // CHECK: ret void
  147. // CHECK: define internal void @[[RED_COMB1]](i8* %0, i8* %1)
  148. // CHECK: fadd float %
  149. // CHECK: store float %{{.+}}, float* %
  150. // CHECK: ret void
  151. // CHECK: define internal void @[[RED_INIT2]](i8* %0)
  152. // CHECK: call i8* @__kmpc_threadprivate_cached(
  153. // CHECK: call i8* @__kmpc_threadprivate_cached(
  154. // CHECK: call void [[OMP_INIT1:@.+]](
  155. // CHECK: ret void
  156. // CHECK: define internal void [[OMP_COMB1:@.+]](%struct.S* noalias %0, %struct.S* noalias %1)
  157. // CHECK: fadd float %
  158. // CHECK: define internal void [[OMP_INIT1]](%struct.S* noalias %0, %struct.S* noalias %1)
  159. // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
  160. // CHECK: define internal void @[[RED_FINI2]](i8* %0)
  161. // CHECK: call i8* @__kmpc_threadprivate_cached(
  162. // CHECK: call void @
  163. // CHECK: ret void
  164. // CHECK: define internal void @[[RED_COMB2]](i8* %0, i8* %1)
  165. // CHECK: call i8* @__kmpc_threadprivate_cached(
  166. // CHECK: call void [[OMP_COMB1]](
  167. // CHECK: ret void
  168. // CHECK: define internal void @[[RED_INIT3]](i8* %0)
  169. // CHECK: store float 0.000000e+00, float* %
  170. // CHECK: ret void
  171. // CHECK: define internal void @[[RED_COMB3]](i8* %0, i8* %1)
  172. // CHECK: fadd float %
  173. // CHECK: store float %{{.+}}, float* %
  174. // CHECK: ret void
  175. // CHECK: define internal void @[[RED_INIT4]](i8* %0)
  176. // CHECK: call i8* @__kmpc_threadprivate_cached(
  177. // CHECK: store float 0.000000e+00, float* %
  178. // CHECK: ret void
  179. // CHECK: define internal void @[[RED_COMB4]](i8* %0, i8* %1)
  180. // CHECK: call i8* @__kmpc_threadprivate_cached(
  181. // CHECK: fadd float %
  182. // CHECK: store float %{{.+}}, float* %
  183. // CHECK: ret void
  184. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT1]]"
  185. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB1]]"
  186. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT2]]"
  187. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_FINI2]]"
  188. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB2]]"
  189. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT3]]"
  190. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB3]]"
  191. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_INIT4]]"
  192. // CHECK-DAG: !DISubprogram(linkageName: "[[RED_COMB4]]"