[clang] f97b843 - [OpenMP] Fix non-determinism in clang copyin codegen

Giorgis Georgakoudis via cfe-commits cfe-commits at lists.llvm.org
Wed May 5 19:24:10 PDT 2021


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 =


        


More information about the cfe-commits mailing list