[Mlir-commits] [mlir] [mlir][scf] fix loop specialization crash when an scf.for result is used (PR #236046)
Matthias Springer
llvmlistbot at llvm.org
Sat Oct 31 10:49:46 PDT 2026
================
@@ -103,9 +103,19 @@ static void specializeForLoopForUnrolling(ForOp op) {
Value cond = arith::CmpIOp::create(b, op.getLoc(), arith::CmpIPredicate::eq,
bound, constant);
map.map(bound, constant);
- auto ifOp = scf::IfOp::create(b, op.getLoc(), cond, /*withElseRegion=*/true);
- ifOp.getThenBodyBuilder().clone(*op.getOperation(), map);
- ifOp.getElseBodyBuilder().clone(*op.getOperation());
+ auto ifOp = scf::IfOp::create(b, op.getLoc(), op->getResultTypes(), cond,
+ /*withElseRegion=*/true);
+
+ OpBuilder thenB = ifOp.getThenBodyBuilder();
+ Operation *thenLoop = thenB.clone(*op.getOperation(), map);
+ OpBuilder elseB = ifOp.getElseBodyBuilder();
+ Operation *elseLoop = elseB.clone(*op.getOperation());
+
+ if (op->getNumResults() > 0) {
+ scf::YieldOp::create(thenB, op.getLoc(), thenLoop->getResults());
----------------
matthias-springer wrote:
Doesn't `IfOp::create` already create an `scf.yield` op?
https://github.com/llvm/llvm-project/pull/236046
More information about the Mlir-commits
mailing list