[llvm] [mlir] [Utils][mlir] Fix interaction between CodeExtractor and OpenMPIRBuilder (PR #145051)

Kareem Ergawy via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 23 02:28:30 PDT 2025


================
@@ -1868,8 +1866,14 @@ CallInst *CodeExtractor::emitReplacerCall(
   // This takes place of the original loop
   BasicBlock *codeReplacer =
       BasicBlock::Create(Context, "codeRepl", oldFunction, ReplIP);
+  // In cases with multiple levels of outlining, e.g. with OpenMP,
+  // AllocationBlock may end up in a function different than oldFunction. We
+  // need to make sure we do not use it in those cases, otherwise the alloca
+  // will end up in a different function from its users and break the module.
   BasicBlock *AllocaBlock =
-      AllocationBlock ? AllocationBlock : &oldFunction->getEntryBlock();
+      (AllocationBlock && oldFunction == AllocationBlock->getParent())
+          ? AllocationBlock
+          : &oldFunction->getEntryBlock();
----------------
ergawy wrote:

`AllocationBlock` is assigned on construction of the `CodeExtractor` object. Should we instead make sure that we pass a suitable basic block when we construct the code extractor object?

https://github.com/llvm/llvm-project/pull/145051


More information about the llvm-commits mailing list