[Mlir-commits] [mlir] [mlir][IR] Adjust insertion block when splitting blocks / moving ops (PR #150819)
Markus Böck
llvmlistbot at llvm.org
Sun Jul 27 03:26:07 PDT 2025
================
@@ -348,14 +349,29 @@ void RewriterBase::mergeBlocks(Block *source, Block *dest,
/// Split the operations starting at "before" (inclusive) out of the given
/// block into a new block, and return it.
Block *RewriterBase::splitBlock(Block *block, Block::iterator before) {
+ Block *newBlock;
+
+ // If the current insertion point is at or after the split point, adjust the
+ // insertion point to the new block.
+ bool moveIpToNewBlock = getBlock() == block &&
+ !block->isBeforeInBlock(getInsertionPoint(), before);
+ auto adjustInsertionPoint = llvm::make_scope_exit([&]() {
+ if (getInsertionPoint() == block->end()) {
+ // If the insertion point is at the end of the block, move it to the end
+ // of the new block.
+ setInsertionPointToEnd(newBlock);
+ } else if (moveIpToNewBlock) {
+ setInsertionPoint(newBlock, getInsertionPoint());
+ }
+ });
----------------
zero9178 wrote:
Is there an easy way we can test the logic here?
https://github.com/llvm/llvm-project/pull/150819
More information about the Mlir-commits
mailing list