[llvm] [mlir] [Utils][mlir] Fix interaction between CodeExtractor and OpenMPIRBuilder (PR #145051)
Tom Eccles via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 07:29:09 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();
----------------
tblah wrote:
Thanks for the update.
Sorry to be difficult but looking at this change gave me an idea: I think this situation just shouldn't ever happen.
Say we have something like this
```
omp.op1 {
other.op1
omp.op2 {
other.op2
}
other.op3
}
```
If the lowering for omp.op2 is trying to put allocas in the alloca region for op1 then yes both of those could be outlined to different functions. But I don't think this should ever happen. If omp.op2 is expecting to be outlined, I think it should define its own alloca insertion point on the alloca stack.
I suspect one of the operations in your test needs to add an insertion point to the stack.
https://github.com/llvm/llvm-project/pull/145051
More information about the llvm-commits
mailing list