[clang] Fix computation of number of dependencies using OpenMP iterator,

by Raul Penacoba.

The size of kmp_depend_info and the number of dependencies are computed multiplying the iterator sizes, which not right.
Now size is computed as:

itersize1*numclausedeps1 + itersize2*numclausedeps2 + ... + itersizeN*numclausedepsN

where itersizeX is the size of the iterator and numclausedepsX the number of dependencies in that depend clause.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D111045
This commit is contained in:
Alexey Bataev 2021-10-04 06:28:09 -07:00
parent 92ac146bb9
commit bfc8f9e9b0
3 changed files with 36 additions and 5 deletions

View File

@ -4882,7 +4882,7 @@ std::pair<llvm::Value *, Address> 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<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
continue;
}
// Include number of iterations, if any.
if (const auto *IE = cast_or_null<OMPIteratorExpr>(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;

View File

@ -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])
{
}
}

View File

@ -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]],