diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp --- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp +++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp @@ -2793,7 +2793,7 @@ // __kmpc_target_init or // __kmpc_target_deinit call. We will answer this one with the internal // state. - if (!isValidState()) + if (!SPMDCompatibilityTracker.isValidState()) return nullptr; if (!SPMDCompatibilityTracker.isAtFixpoint()) { if (AA) @@ -3209,17 +3209,19 @@ }; bool UsedAssumedInformationInCheckRWInst = false; - if (!A.checkForAllReadWriteInstructions( - CheckRWInst, *this, UsedAssumedInformationInCheckRWInst)) - SPMDCompatibilityTracker.indicatePessimisticFixpoint(); + if (!SPMDCompatibilityTracker.isAtFixpoint()) + if (!A.checkForAllReadWriteInstructions( + CheckRWInst, *this, UsedAssumedInformationInCheckRWInst)) + SPMDCompatibilityTracker.indicatePessimisticFixpoint(); // Callback to check a call instruction. + bool AllSPMDStatesWereFixed = true; auto CheckCallInst = [&](Instruction &I) { auto &CB = cast(I); auto &CBAA = A.getAAFor( *this, IRPosition::callsite_function(CB), DepClassTy::OPTIONAL); - if (CBAA.getState().isValidState()) - getState() ^= CBAA.getState(); + getState() ^= CBAA.getState(); + AllSPMDStatesWereFixed &= CBAA.SPMDCompatibilityTracker.isAtFixpoint(); return true; }; @@ -3228,6 +3230,12 @@ CheckCallInst, *this, UsedAssumedInformationInCheckCallInst)) return indicatePessimisticFixpoint(); + // If we haven't used any assumed information for the SPMD state we can fix + // it. + if (!UsedAssumedInformationInCheckRWInst && + !UsedAssumedInformationInCheckCallInst && AllSPMDStatesWereFixed) + SPMDCompatibilityTracker.indicateOptimisticFixpoint(); + return StateBefore == getState() ? ChangeStatus::UNCHANGED : ChangeStatus::CHANGED; }