[llvm-branch-commits] [cfe-branch] r318105 - Merging r311013:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 13 15:12:35 PST 2017


Author: tstellar
Date: Mon Nov 13 15:12:35 2017
New Revision: 318105

URL: http://llvm.org/viewvc/llvm-project?rev=318105&view=rev
Log:
Merging r311013:

------------------------------------------------------------------------
r311013 | abataev | 2017-08-16 08:58:46 -0700 (Wed, 16 Aug 2017) | 7 lines

[OPENMP] Fix for PR28581: OpenMP linear clause - wrong results.

If worksharing construct has at least one linear item, an implicit
synchronization point must be emitted to avoid possible conflict with
the loading/storing values to the original variables. Added implicit
barrier if the linear item is found before actual start of the
worksharing construct.
------------------------------------------------------------------------

Modified:
    cfe/branches/release_50/lib/CodeGen/CGStmtOpenMP.cpp
    cfe/branches/release_50/lib/CodeGen/CodeGenFunction.h
    cfe/branches/release_50/test/OpenMP/for_linear_codegen.cpp

Modified: cfe/branches/release_50/lib/CodeGen/CGStmtOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/CodeGen/CGStmtOpenMP.cpp?rev=318105&r1=318104&r2=318105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/branches/release_50/lib/CodeGen/CGStmtOpenMP.cpp Mon Nov 13 15:12:35 2017
@@ -1210,12 +1210,14 @@ void CodeGenFunction::EmitOMPInnerLoop(
   EmitBlock(LoopExit.getBlock());
 }
 
-void CodeGenFunction::EmitOMPLinearClauseInit(const OMPLoopDirective &D) {
+bool CodeGenFunction::EmitOMPLinearClauseInit(const OMPLoopDirective &D) {
   if (!HaveInsertPoint())
-    return;
+    return false;
   // Emit inits for the linear variables.
+  bool HasLinears = false;
   for (const auto *C : D.getClausesOfKind<OMPLinearClause>()) {
     for (auto *Init : C->inits()) {
+      HasLinears = true;
       auto *VD = cast<VarDecl>(cast<DeclRefExpr>(Init)->getDecl());
       if (auto *Ref = dyn_cast<DeclRefExpr>(VD->getInit()->IgnoreImpCasts())) {
         AutoVarEmission Emission = EmitAutoVarAlloca(*VD);
@@ -1240,6 +1242,7 @@ void CodeGenFunction::EmitOMPLinearClaus
         EmitIgnoredExpr(CS);
       }
   }
+  return HasLinears;
 }
 
 void CodeGenFunction::EmitOMPLinearClauseFinal(
@@ -1529,7 +1532,7 @@ void CodeGenFunction::EmitOMPSimdDirecti
     CGF.EmitOMPSimdInit(S);
 
     emitAlignedClause(CGF, S);
-    CGF.EmitOMPLinearClauseInit(S);
+    (void)CGF.EmitOMPLinearClauseInit(S);
     {
       OMPPrivateScope LoopScope(CGF);
       CGF.EmitOMPPrivateLoopCounters(S, LoopScope);
@@ -2147,7 +2150,7 @@ bool CodeGenFunction::EmitOMPWorksharing
 
     llvm::DenseSet<const Expr *> EmittedFinals;
     emitAlignedClause(*this, S);
-    EmitOMPLinearClauseInit(S);
+    bool HasLinears = EmitOMPLinearClauseInit(S);
     // Emit helper vars inits.
 
     std::pair<LValue, LValue> Bounds = CodeGenLoopBounds(*this, S);
@@ -2161,7 +2164,7 @@ bool CodeGenFunction::EmitOMPWorksharing
     // Emit 'then' code.
     {
       OMPPrivateScope LoopScope(*this);
-      if (EmitOMPFirstprivateClause(S, LoopScope)) {
+      if (EmitOMPFirstprivateClause(S, LoopScope) || HasLinears) {
         // Emit implicit barrier to synchronize threads and avoid data races on
         // initialization of firstprivate variables and post-update of
         // lastprivate variables.

Modified: cfe/branches/release_50/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/lib/CodeGen/CodeGenFunction.h?rev=318105&r1=318104&r2=318105&view=diff
==============================================================================
--- cfe/branches/release_50/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/branches/release_50/lib/CodeGen/CodeGenFunction.h Mon Nov 13 15:12:35 2017
@@ -2761,7 +2761,9 @@ public:
   /// and initializes them with the values according to OpenMP standard.
   ///
   /// \param D Directive (possibly) with the 'linear' clause.
-  void EmitOMPLinearClauseInit(const OMPLoopDirective &D);
+  /// \return true if at least one linear variable is found that should be
+  /// initialized with the value of the original variable, false otherwise.
+  bool EmitOMPLinearClauseInit(const OMPLoopDirective &D);
 
   typedef const llvm::function_ref<void(CodeGenFunction & /*CGF*/,
                                         llvm::Value * /*OutlinedFn*/,

Modified: cfe/branches/release_50/test/OpenMP/for_linear_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_50/test/OpenMP/for_linear_codegen.cpp?rev=318105&r1=318104&r2=318105&view=diff
==============================================================================
--- cfe/branches/release_50/test/OpenMP/for_linear_codegen.cpp (original)
+++ cfe/branches/release_50/test/OpenMP/for_linear_codegen.cpp Mon Nov 13 15:12:35 2017
@@ -422,6 +422,7 @@ int main() {
 // CHECK: [[A_PRIV:%.+]] = alloca i{{[0-9]+}},
 // CHECK: [[B_PRIV:%.+]] = alloca i{{[0-9]+}},
 // CHECK: [[C_PRIV:%.+]] = alloca i{{[0-9]+}},
+// CHECK: call void @__kmpc_barrier(
 // CHECK: store i{{[0-9]+}}* [[A_PRIV]], i{{[0-9]+}}** [[REFA:%.+]],
 // CHECK: store i{{[0-9]+}}* [[C_PRIV]], i{{[0-9]+}}** [[REFC:%.+]],
 // CHECK: call void @__kmpc_for_static_init_4(




More information about the llvm-branch-commits mailing list