diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index 5276200f47a6d0..e51d196b870ffc 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -4882,7 +4882,7 @@ std::pair CGOpenMPRuntime::emitDependClause( bool HasRegularWithIterators = false; llvm::Value *NumOfDepobjElements = llvm::ConstantInt::get(CGF.IntPtrTy, 0); llvm::Value *NumOfRegularWithIterators = - llvm::ConstantInt::get(CGF.IntPtrTy, 1); + llvm::ConstantInt::get(CGF.IntPtrTy, 0); // Calculate number of depobj dependecies and regular deps with the iterators. for (const OMPTaskDataTy::DependData &D : Dependencies) { if (D.DepKind == OMPC_DEPEND_depobj) { @@ -4896,12 +4896,15 @@ std::pair CGOpenMPRuntime::emitDependClause( continue; } // Include number of iterations, if any. + if (const auto *IE = cast_or_null(D.IteratorExpr)) { for (unsigned I = 0, E = IE->numOfIterators(); I < E; ++I) { llvm::Value *Sz = CGF.EmitScalarExpr(IE->getHelper(I).Upper); Sz = CGF.Builder.CreateIntCast(Sz, CGF.IntPtrTy, /*isSigned=*/false); + llvm::Value *NumClauseDeps = CGF.Builder.CreateNUWMul( + Sz, llvm::ConstantInt::get(CGF.IntPtrTy, D.DepExprs.size())); NumOfRegularWithIterators = - CGF.Builder.CreateNUWMul(NumOfRegularWithIterators, Sz); + CGF.Builder.CreateNUWAdd(NumOfRegularWithIterators, NumClauseDeps); } HasRegularWithIterators = true; continue; diff --git a/clang/test/OpenMP/depend_iterator_bug.c b/clang/test/OpenMP/depend_iterator_bug.c new file mode 100644 index 00000000000000..b7470f00376165 --- /dev/null +++ b/clang/test/OpenMP/depend_iterator_bug.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -verify -fopenmp -triple x86_64-unknown-linux-gnu \ +// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s + +// expected-no-diagnostics + +int x[100]; +int y[100]; + +// CHECK-LABEL: @many_iterators_single_clause( +// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, align 16 +// CHECK: = call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null) +void many_iterators_single_clause() { + #pragma omp task depend(iterator(j=0:5), in: x[j], y[j]) + { + } +} + +// CHECK-LABEL: @many_iterators_many_clauses( +// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, align 16 +// CHECK: = call i32 @__kmpc_omp_task_with_deps(%struct.ident_t* {{.*}}, i32 {{.*}}, i8* {{.*}}, i32 10, i8* {{.*}}, i32 0, i8* null) +void many_iterators_many_clauses() { + #pragma omp task depend(iterator(j=0:5), in: x[j]) \ + depend(iterator(j=0:5), in: y[j]) + { + } +} diff --git a/clang/test/OpenMP/task_codegen.c b/clang/test/OpenMP/task_codegen.c index f53fd75f670099..d813ba21f8f32e 100644 --- a/clang/test/OpenMP/task_codegen.c +++ b/clang/test/OpenMP/task_codegen.c @@ -150,10 +150,12 @@ for (int i = 0; i < 10; ++i) // CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1 // CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 [[EB_SUB_2_ADD_1_SUB]], 2 // CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64 - // CHECK: [[NELEMS:%.+]] = mul nuw i64 1, [[ELEMS]] + // CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS]], 1 - // TOTAL_NUMBER_OF_ELEMENTS = NELEMS + 0; - // CHECK: [[TOTAL:%.+]] = add nuw i64 [[NELEMS]], 0 + // ITERATOR_TOTAL = NELEMS + 0; + // CHECK: [[ITERATOR_TOTAL:%.+]] = add nuw i64 0, [[NELEMS]] + // NELEMS = ITERATOR_TOTAL + non-iterator-deps (=0) + // CHECK: [[TOTAL:%.+]] = add nuw i64 [[ITERATOR_TOTAL]], 0 // %struct.kmp_depend_info DEPS[TOTAL]; // CHECK: [[DEPS:%.+]] = alloca %struct.kmp_depend_info, i64 [[TOTAL]],