[PATCH] D111045: [clang] Fix computation of number of dependencies using OpenMP iterator

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbfc8f9e9b0bd: [clang] Fix computation of number of dependencies using OpenMP iterator, (authored by ABataev).
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111045/new/

https://reviews.llvm.org/D111045

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


Index: clang/test/OpenMP/task_codegen.c
===================================================================
--- clang/test/OpenMP/task_codegen.c
+++ clang/test/OpenMP/task_codegen.c
@@ -150,10 +150,12 @@
   // 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]],
Index: clang/test/OpenMP/depend_iterator_bug.c
===================================================================
--- /dev/null
+++ 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])
+    {
+    }
+}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4882,7 +4882,7 @@
   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 @@
       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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111045.376886.patch
Type: text/x-patch
Size: 3643 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211004/a9c80433/attachment.bin>


More information about the cfe-commits mailing list