Skip to content

Commit f97b843

Browse files
committed
[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
1 parent 7b73cd6 commit f97b843

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,14 @@ bool CodeGenFunction::EmitOMPCopyinClause(const OMPExecutableDirective &D) {
10061006
// need to copy data.
10071007
CopyBegin = createBasicBlock("copyin.not.master");
10081008
CopyEnd = createBasicBlock("copyin.not.master.end");
1009+
// TODO: Avoid ptrtoint conversion.
1010+
auto *MasterAddrInt =
1011+
Builder.CreatePtrToInt(MasterAddr.getPointer(), CGM.IntPtrTy);
1012+
auto *PrivateAddrInt =
1013+
Builder.CreatePtrToInt(PrivateAddr.getPointer(), CGM.IntPtrTy);
10091014
Builder.CreateCondBr(
1010-
Builder.CreateICmpNE(
1011-
Builder.CreatePtrToInt(MasterAddr.getPointer(), CGM.IntPtrTy),
1012-
Builder.CreatePtrToInt(PrivateAddr.getPointer(),
1013-
CGM.IntPtrTy)),
1014-
CopyBegin, CopyEnd);
1015+
Builder.CreateICmpNE(MasterAddrInt, PrivateAddrInt), CopyBegin,
1016+
CopyEnd);
10151017
EmitBlock(CopyBegin);
10161018
}
10171019
const auto *SrcVD =

0 commit comments

Comments
 (0)