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

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 4 07:07:48 PDT 2021


Author: Alexey Bataev
Date: 2021-10-04T07:06:51-07:00
New Revision: bfc8f9e9b0bd2279ee3398ee62f255360a89f0e9

URL: https://github.com/llvm/llvm-project/commit/bfc8f9e9b0bd2279ee3398ee62f255360a89f0e9
DIFF: https://github.com/llvm/llvm-project/commit/bfc8f9e9b0bd2279ee3398ee62f255360a89f0e9.diff

LOG: [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

Added: 
    clang/test/OpenMP/depend_iterator_bug.c

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/test/OpenMP/task_codegen.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 5276200f47a6d..e51d196b870ff 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -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;

diff  --git a/clang/test/OpenMP/depend_iterator_bug.c b/clang/test/OpenMP/depend_iterator_bug.c
new file mode 100644
index 0000000000000..b7470f0037616
--- /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 f53fd75f67009..d813ba21f8f32 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]],


        


More information about the cfe-commits mailing list