Skip to content

Commit b45379e

Browse files
committed
Fix calculation of dependencies for multi-dimensional iteration space
1 parent 77b2c68 commit b45379e

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,14 +4259,19 @@ std::pair<llvm::Value *, Address> CGOpenMPRuntime::emitDependClause(
42594259
// Include number of iterations, if any.
42604260

42614261
if (const auto *IE = cast_or_null<OMPIteratorExpr>(D.IteratorExpr)) {
4262+
llvm::Value *ClauseIteratorSpace =
4263+
llvm::ConstantInt::get(CGF.IntPtrTy, 1);
42624264
for (unsigned I = 0, E = IE->numOfIterators(); I < E; ++I) {
42634265
llvm::Value *Sz = CGF.EmitScalarExpr(IE->getHelper(I).Upper);
42644266
Sz = CGF.Builder.CreateIntCast(Sz, CGF.IntPtrTy, /*isSigned=*/false);
4265-
llvm::Value *NumClauseDeps = CGF.Builder.CreateNUWMul(
4266-
Sz, llvm::ConstantInt::get(CGF.IntPtrTy, D.DepExprs.size()));
4267-
NumOfRegularWithIterators =
4268-
CGF.Builder.CreateNUWAdd(NumOfRegularWithIterators, NumClauseDeps);
4267+
ClauseIteratorSpace = CGF.Builder.CreateNUWMul(Sz, ClauseIteratorSpace);
42694268
}
4269+
llvm::Value *NumClauseDeps =
4270+
CGF.Builder.CreateNUWMul(
4271+
ClauseIteratorSpace,
4272+
llvm::ConstantInt::get(CGF.IntPtrTy, D.DepExprs.size()));
4273+
NumOfRegularWithIterators =
4274+
CGF.Builder.CreateNUWAdd(NumOfRegularWithIterators, NumClauseDeps);
42704275
HasRegularWithIterators = true;
42714276
continue;
42724277
}

clang/test/OpenMP/depend_iterator_bug.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
int x[100];
77
int y[100];
8+
int z[100][100];
89

910
// CHECK-LABEL: @many_iterators_single_clause(
1011
// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 10, align 16
@@ -24,3 +25,31 @@ void many_iterators_many_clauses(void) {
2425
{
2526
}
2627
}
28+
29+
// CHECK-LABEL: @multidim_iterators_clause1(
30+
// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 1, align 16
31+
// CHECK: = call i32 @__kmpc_omp_task_with_deps(ptr {{.*}}, i32 {{.*}}, ptr {{.*}}, i32 1, ptr {{.*}}, i32 0, ptr null)
32+
void multidim_iterators_clause1(void) {
33+
#pragma omp task depend(iterator(i=0:1, j=0:1), in: z[i][j])
34+
{
35+
}
36+
}
37+
38+
// CHECK-LABEL: @multidim_iterators_offset_clause(
39+
// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 1, align 16
40+
// CHECK: = call i32 @__kmpc_omp_task_with_deps(ptr {{.*}}, i32 {{.*}}, ptr {{.*}}, i32 1, ptr {{.*}}, i32 0, ptr null)
41+
void multidim_iterators_offset_clause(void) {
42+
#pragma omp task depend(iterator(i=5:6, j=10:11), in: z[i][j])
43+
{
44+
}
45+
}
46+
47+
// CHECK-LABEL: @multidim_iterators_clause25(
48+
// CHECK: [[VLA:%.*]] = alloca [[STRUCT_KMP_DEPEND_INFO:%.*]], i64 25, align 16
49+
// CHECK: = call i32 @__kmpc_omp_task_with_deps(ptr {{.*}}, i32 {{.*}}, ptr {{.*}}, i32 25, ptr {{.*}}, i32 0, ptr null)
50+
void multidim_iterators_clause25(void) {
51+
#pragma omp task depend(iterator(i=0:5, j=0:5), in: z[i][j])
52+
{
53+
}
54+
}
55+

clang/test/OpenMP/task_codegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ for (int i = 0; i < 10; ++i)
139139
// CHECK: [[EB_SUB_2_ADD_1_SUB:%.+]] = sub i32 [[EB_SUB_2_ADD]], 1
140140
// CHECK: [[EB_SUB_2_ADD_1_SUB_2_DIV:%.+]] = udiv i32 [[EB_SUB_2_ADD_1_SUB]], 2
141141
// CHECK: [[ELEMS:%.+]] = zext i32 [[EB_SUB_2_ADD_1_SUB_2_DIV]] to i64
142-
// CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS]], 1
142+
// CHECK: [[ELEMS2:%.+]] = mul nuw i64 [[ELEMS]], 1
143+
// CHECK: [[NELEMS:%.+]] = mul nuw i64 [[ELEMS2]], 1
143144

144145
// ITERATOR_TOTAL = NELEMS + 0;
145146
// CHECK: [[ITERATOR_TOTAL:%.+]] = add nuw i64 0, [[NELEMS]]

0 commit comments

Comments
 (0)