[OPENMP] Fix the address of the original variable in task reductions.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 9 Mar 2018 15:20:30 +0000 (15:20 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 9 Mar 2018 15:20:30 +0000 (15:20 +0000)
If initialization of the task reductions requires pointer to original
variable, which is stored in the threadprivate storage, we used the
address of this pointer instead.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327136 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGOpenMPRuntime.cpp
test/OpenMP/taskloop_reduction_codegen.cpp

index f9dab90f398a941b7b8302ad581b939e8dfd834b..708f0abd08d30781df354d0e09b97bad56751f6b 100644 (file)
@@ -5422,6 +5422,9 @@ static llvm::Value *emitReduceInitFunction(CodeGenModule &CGM,
         CGM.getOpenMPRuntime().getAddrOfArtificialThreadPrivate(
             CGF, CGM.getContext().VoidPtrTy,
             generateUniqueName(CGM, "reduction", RCG.getRefExpr(N)));
+    SharedAddr = CGF.EmitLoadOfPointer(
+        SharedAddr,
+        CGM.getContext().VoidPtrTy.castAs<PointerType>()->getTypePtr());
     SharedLVal = CGF.MakeAddrLValue(SharedAddr, CGM.getContext().VoidPtrTy);
   } else {
     SharedLVal = CGF.MakeNaturalAlignAddrLValue(
index 2623d932c7f024073ff1832da62e33e6d3b00781..fe261d4e064e0cefa20a739eed41c14b32cdbcdd 100644 (file)
@@ -164,7 +164,9 @@ sum = 0.0;
 
 // CHECK: define internal void @[[RED_INIT2]](i8*)
 // CHECK: call i8* @__kmpc_threadprivate_cached(
-// CHECK: call i8* @__kmpc_threadprivate_cached(
+// CHECK: [[ORIG_PTR_ADDR:%.+]] = call i8* @__kmpc_threadprivate_cached(
+// CHECK: [[ORIG_PTR_REF:%.+]] = bitcast i8* [[ORIG_PTR_ADDR]] to i8**
+// CHECK: load i8*, i8** [[ORIG_PTR_REF]],
 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(
 // CHECK: ret void