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