@@ -3188,6 +3188,34 @@ struct AAKernelInfoFunction : AAKernelInfo {
3188
3188
->setDebugLoc (DL);
3189
3189
};
3190
3190
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
+
3191
3219
SmallVector<std::pair<Instruction *, Instruction *>, 4 > GuardedRegions;
3192
3220
3193
3221
for (Instruction *GuardedI : SPMDCompatibilityTracker) {
@@ -4244,7 +4272,6 @@ void OpenMPOpt::registerAAs(bool IsModulePass) {
4244
4272
DepClassTy::NONE, /* ForceUpdate */ false ,
4245
4273
/* UpdateAfterInit */ false );
4246
4274
4247
-
4248
4275
registerFoldRuntimeCall (OMPRTL___kmpc_is_generic_main_thread_id);
4249
4276
registerFoldRuntimeCall (OMPRTL___kmpc_is_spmd_exec_mode);
4250
4277
registerFoldRuntimeCall (OMPRTL___kmpc_parallel_level);
0 commit comments