Author: Giorgis Georgakoudis
Date: 2021-05-05T19:24:03-07:00
New Revision: f97b843d8819f824dcc1b6afa746ce9a7a386db3

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

LOG: [OpenMP] Fix non-determinism in clang copyin codegen

Codegen for OpeMP copyin has non-deterministic IR output due to the unspecified 
evaluation order in a codegen conditional branch, which makes automatic test 
generation unreliable. This patch refactors codegen code to avoid this 
non-determinism.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D101952

Added: 
    

Modified: 
    clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 1f714b01b3f1c..344fa90253ec3 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1006,12 +1006,14 @@ bool CodeGenFunction::EmitOMPCopyinClause(const 
OMPExecutableDirective &D) {
           // need to copy data.
           CopyBegin = createBasicBlock("copyin.not.master");
           CopyEnd = createBasicBlock("copyin.not.master.end");
+          // TODO: Avoid ptrtoint conversion.
+          auto *MasterAddrInt =
+              Builder.CreatePtrToInt(MasterAddr.getPointer(), CGM.IntPtrTy);
+          auto *PrivateAddrInt =
+              Builder.CreatePtrToInt(PrivateAddr.getPointer(), CGM.IntPtrTy);
           Builder.CreateCondBr(
-              Builder.CreateICmpNE(
-                  Builder.CreatePtrToInt(MasterAddr.getPointer(), 
CGM.IntPtrTy),
-                  Builder.CreatePtrToInt(PrivateAddr.getPointer(),
-                                         CGM.IntPtrTy)),
-              CopyBegin, CopyEnd);
+              Builder.CreateICmpNE(MasterAddrInt, PrivateAddrInt), CopyBegin,
+              CopyEnd);
           EmitBlock(CopyBegin);
         }
         const auto *SrcVD =


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to