[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.

llvm-svn: 327136

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

index f9dab90..708f0ab 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 2623d93..fe261d4 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