Skip to content

Commit 99ea8ac

Browse files
committed
Reapply "[OpenMP] Group side-effects to improve guarding efficiency"
This reapplies ca134c3, effectively reverting commit d2f206e. Minor test changes to make the test pass.
1 parent c09fbbd commit 99ea8ac

File tree

2 files changed

+448
-1
lines changed

2 files changed

+448
-1
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3188,6 +3188,34 @@ struct AAKernelInfoFunction : AAKernelInfo {
31883188
->setDebugLoc(DL);
31893189
};
31903190

3191+
auto &AllocSharedRFI = OMPInfoCache.RFIs[OMPRTL___kmpc_alloc_shared];
3192+
SmallPtrSet<BasicBlock *, 8> Visited;
3193+
for (Instruction *GuardedI : SPMDCompatibilityTracker) {
3194+
BasicBlock *BB = GuardedI->getParent();
3195+
if (!Visited.insert(BB).second)
3196+
continue;
3197+
3198+
SmallVector<std::pair<Instruction *, Instruction *>> Reorders;
3199+
Instruction *LastEffect = nullptr;
3200+
BasicBlock::reverse_iterator IP = BB->rbegin(), IPEnd = BB->rend();
3201+
while (++IP != IPEnd) {
3202+
if (!IP->mayHaveSideEffects() && !IP->mayReadFromMemory())
3203+
continue;
3204+
Instruction *I = &*IP;
3205+
if (OpenMPOpt::getCallIfRegularCall(*I, &AllocSharedRFI))
3206+
continue;
3207+
if (!I->user_empty() || !SPMDCompatibilityTracker.contains(I)) {
3208+
LastEffect = nullptr;
3209+
continue;
3210+
}
3211+
if (LastEffect)
3212+
Reorders.push_back({I, LastEffect});
3213+
LastEffect = &*IP;
3214+
}
3215+
for (auto &Reorder : Reorders)
3216+
Reorder.first->moveBefore(Reorder.second);
3217+
}
3218+
31913219
SmallVector<std::pair<Instruction *, Instruction *>, 4> GuardedRegions;
31923220

31933221
for (Instruction *GuardedI : SPMDCompatibilityTracker) {
@@ -4244,7 +4272,6 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
42444272
DepClassTy::NONE, /* ForceUpdate */ false,
42454273
/* UpdateAfterInit */ false);
42464274

4247-
42484275
registerFoldRuntimeCall(OMPRTL___kmpc_is_generic_main_thread_id);
42494276
registerFoldRuntimeCall(OMPRTL___kmpc_is_spmd_exec_mode);
42504277
registerFoldRuntimeCall(OMPRTL___kmpc_parallel_level);

0 commit comments

Comments
 (0)