[Mlir-commits] [mlir] befd665 - [mlir][scf] Declare ControlFlow as a dependent dialect (#216852)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Aug 31 01:53:22 PDT 2026
Author: Alessandro Potenza
Date: 2026-08-31T10:53:17+02:00
New Revision: befd665eb7058e6c6fab2f82816fe5317f457273
URL: https://github.com/llvm/llvm-project/commit/befd665eb7058e6c6fab2f82816fe5317f457273
DIFF: https://github.com/llvm/llvm-project/commit/befd665eb7058e6c6fab2f82816fe5317f457273.diff
LOG: [mlir][scf] Declare ControlFlow as a dependent dialect (#216852)
The canonicalization of a multi-block `scf.execute_region` creates
`cf.br`, but the SCF dialect does not declare `cf::ControlFlowDialect`
as a dependent dialect.
When nothing else has loaded ControlFlow, `mlir-opt --canonicalize`
fails with
LLVM ERROR: cf.br created with unregistered dialect.
Prepending an unrelated function that merely mentions `cf.br` makes the
same input canonicalize cleanly, which is the symptom `dependentDialects`
prevents.
The test needs a non-`func.func` parent: Func's inliner extension
already loads ControlFlow, which is why no in-tree test caught this.
Assisted-by: Claude (Anthropic)
Added:
mlir/test/Dialect/SCF/canonicalize-dependent-dialects.mlir
Modified:
mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
index 2fe8046a92463..b0a34989b6433 100644
--- a/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
+++ b/mlir/include/mlir/Dialect/SCF/IR/SCFOps.td
@@ -42,7 +42,9 @@ def SCF_Dialect : Dialect {
and then lowered to some final target like LLVM or SPIR-V.
}];
- let dependentDialects = ["arith::ArithDialect"];
+ // The canonicalization of a multi-block `scf.execute_region` materializes
+ // `cf.br` operations, so the ControlFlow dialect must always be loaded.
+ let dependentDialects = ["arith::ArithDialect", "cf::ControlFlowDialect"];
}
// Base class for SCF dialect ops.
diff --git a/mlir/test/Dialect/SCF/canonicalize-dependent-dialects.mlir b/mlir/test/Dialect/SCF/canonicalize-dependent-dialects.mlir
new file mode 100644
index 0000000000000..c8579167bc071
--- /dev/null
+++ b/mlir/test/Dialect/SCF/canonicalize-dependent-dialects.mlir
@@ -0,0 +1,27 @@
+// RUN: mlir-opt %s --canonicalize | FileCheck %s
+
+// Canonicalizing a multi-block `scf.execute_region` materializes `cf.br` ops,
+// so the SCF dialect has to declare a dependency on the ControlFlow dialect.
+// This test deliberately contains no `cf` operation and does not use
+// `func.func`: parsing a `cf` operation, or loading the Func dialect (whose
+// inliner extension loads ControlFlow), would load the dialect for unrelated
+// reasons and mask the missing dependency.
+
+// CHECK-LABEL: llvm.func @multi_block_execute_region
+// CHECK-NOT: scf.execute_region
+// CHECK: llvm.cond_br
+// CHECK: llvm.store
+// CHECK: cf.br
+// CHECK: cf.br
+// CHECK: llvm.return
+llvm.func @multi_block_execute_region(%c: i1, %p: !llvm.ptr, %x: i64) {
+ scf.execute_region {
+ llvm.cond_br %c, ^bb1, ^bb2
+ ^bb1:
+ llvm.store %x, %p : i64, !llvm.ptr
+ scf.yield
+ ^bb2:
+ scf.yield
+ }
+ llvm.return
+}
More information about the Mlir-commits
mailing list