Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mlir/lib/Conversion/LoopToStandard/LoopToStandard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
// place it before the continuation block, and branch to it.
auto &thenRegion = ifOp.thenRegion();
auto *thenBlock = &thenRegion.front();
rewriter.eraseOp(thenRegion.back().getTerminator());
auto thenTerminator = thenRegion.back().getTerminator();
continueBlock->addArguments(thenTerminator->getOperandTypes());
auto thenYieldValues = thenTerminator->getOperands();
rewriter.eraseOp(thenTerminator);
rewriter.setInsertionPointToEnd(&thenRegion.back());
rewriter.create<BranchOp>(loc, continueBlock);
rewriter.inlineRegionBefore(thenRegion, continueBlock);
Expand All @@ -256,9 +259,14 @@ LogicalResult IfLowering::matchAndRewrite(IfOp ifOp,
auto &elseRegion = ifOp.elseRegion();
if (!elseRegion.empty()) {
elseBlock = &elseRegion.front();
rewriter.eraseOp(elseRegion.back().getTerminator());
auto elseTerminator = elseRegion.back().getTerminator();
assert(elseTerminator->getOperandTypes() ==
thenTerminator->getOperandTypes() &&
"Yield values from thenBlock and elseBlock mismatch");
auto elseYieldValues = elseTerminator->getOperands();
rewriter.eraseOp(elseTerminator);
rewriter.setInsertionPointToEnd(&elseRegion.back());
rewriter.create<BranchOp>(loc, continueBlock);
rewriter.create<BranchOp>(loc, continueBlock, elseYieldValues);
rewriter.inlineRegionBefore(elseRegion, continueBlock);
}

Expand Down