[Mlir-commits] [mlir] 933a9a8 - [mlir][scf] Keep scf.yield locations when lowering scf.execute_region (#228575)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Oct 5 00:41:46 PDT 2026
Author: jeanPerier
Date: 2026-10-05T09:41:28+02:00
New Revision: 933a9a8369cddcc9c293f0c4002612d10070484e
URL: https://github.com/llvm/llvm-project/commit/933a9a8369cddcc9c293f0c4002612d10070484e
DIFF: https://github.com/llvm/llvm-project/commit/933a9a8369cddcc9c293f0c4002612d10070484e.diff
LOG: [mlir][scf] Keep scf.yield locations when lowering scf.execute_region (#228575)
The branches replacing the scf.yield terminators of an
scf.execute_region used the location of the scf.execute_region. Use the
location of the scf.yield they replace instead.
Added:
mlir/test/Conversion/SCFToControlFlow/execute-region-locations.mlir
Modified:
mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
index 16894f10b5ff1..46beaa20218d7 100644
--- a/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
+++ b/mlir/lib/Conversion/SCFToControlFlow/SCFToControlFlow.cpp
@@ -475,7 +475,7 @@ ExecuteRegionLowering::matchAndRewrite(ExecuteRegionOp op,
if (auto terminator = dyn_cast<scf::YieldOp>(block.getTerminator())) {
ValueRange terminatorOperands = terminator->getOperands();
rewriter.setInsertionPointToEnd(&block);
- cf::BranchOp::create(rewriter, loc, remainingOpsBlock,
+ cf::BranchOp::create(rewriter, terminator.getLoc(), remainingOpsBlock,
terminatorOperands);
rewriter.eraseOp(terminator);
}
diff --git a/mlir/test/Conversion/SCFToControlFlow/execute-region-locations.mlir b/mlir/test/Conversion/SCFToControlFlow/execute-region-locations.mlir
new file mode 100644
index 0000000000000..5dd9bb7794520
--- /dev/null
+++ b/mlir/test/Conversion/SCFToControlFlow/execute-region-locations.mlir
@@ -0,0 +1,23 @@
+// RUN: mlir-opt -convert-scf-to-cf -mlir-print-debuginfo -mlir-print-local-scope %s | FileCheck %s
+
+// The branch entering the region takes the location of the
+// scf.execute_region, while each branch leaving it keeps the location of the
+// scf.yield it replaces.
+
+// CHECK-LABEL: func @execute_region_locations
+// CHECK: cf.br ^{{.*}} loc("op")
+// CHECK: cf.cond_br {{.*}} loc("cond")
+// CHECK: cf.br ^[[CONT:bb[0-9]+]] loc("yield1")
+// CHECK: cf.br ^[[CONT]] loc("yield2")
+// CHECK: ^[[CONT]]:
+// CHECK: return
+func.func @execute_region_locations(%cond: i1) {
+ scf.execute_region {
+ cf.cond_br %cond, ^bb1, ^bb2 loc("cond")
+ ^bb1:
+ scf.yield loc("yield1")
+ ^bb2:
+ scf.yield loc("yield2")
+ } loc("op")
+ return
+}
More information about the Mlir-commits
mailing list