From: Alex Zinenko Date: Tue, 8 Dec 2020 22:22:36 +0000 (+0100) Subject: [OpenMPIRBuilder] Put the barrier in the exit block in createWorkshapeLoop X-Git-Tag: llvmorg-13-init~3926 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f31704f8ae32a24147fac686f4e922c5c762cfe0;p=platform%2Fupstream%2Fllvm.git [OpenMPIRBuilder] Put the barrier in the exit block in createWorkshapeLoop The original code was inserting the barrier at the location given by the caller. Make sure it is always inserted at the end of the loop exit block instead. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D92849 --- diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp index 6587a36..609184a 100644 --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -1104,7 +1104,8 @@ CanonicalLoopInfo *OpenMPIRBuilder::createStaticWorkshareLoop( // Add the barrier if requested. if (NeedsBarrier) - createBarrier(Loc, omp::Directive::OMPD_for, /* ForceSimpleCall */ false, + createBarrier(LocationDescription(Builder.saveIP(), Loc.DL), + omp::Directive::OMPD_for, /* ForceSimpleCall */ false, /* CheckCancelFlag */ false); CLI->assertOK(); diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 1ad2264..6e69af7 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -1155,6 +1155,13 @@ TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) { // increment and in the statement that adds the lower bound to it. Value *IV = CLI->getIndVar(); EXPECT_EQ(std::distance(IV->use_begin(), IV->use_end()), 3); + + // The exit block should contain the "fini" call and the barrier call, + // plus the call to obtain the thread ID. + BasicBlock *ExitBlock = CLI->getExit(); + size_t NumCallsInExitBlock = + count_if(*ExitBlock, [](Instruction &I) { return isa(I); }); + EXPECT_EQ(NumCallsInExitBlock, 3u); } TEST_F(OpenMPIRBuilderTest, MasterDirective) {