[Mlir-commits] [mlir] [mlir] Handle null region in LoopLikeOpInterface::isDefinedOutsideOfLoop (PR #204521)
Prem C
llvmlistbot at llvm.org
Thu Jun 18 00:43:17 PDT 2026
https://github.com/silent-bytesmith updated https://github.com/llvm/llvm-project/pull/204521
>From cfbf793cd5e822cdb2ca8394a0a476876a48c542 Mon Sep 17 00:00:00 2001
From: silent-bytesmith <cpgh at google.com>
Date: Wed, 17 Jun 2026 23:35:28 -0700
Subject: [PATCH] [mlir] Handle null region in
LoopLikeOpInterface::isDefinedOutsideOfLoop
In LoopLikeOpInterface::isDefinedOutsideOfLoop default implementation,
value.getParentRegion() can return null during signature conversion
rollbacks when blocks/ops are unlinked. Check for null region to avoid
a segmentation fault.
Also, add a regression test for convert-func-to-llvm with index-bitwidth=32
on functions with affine.for loops.
Assisted-by: Antigravity
---
mlir/include/mlir/Interfaces/LoopLikeInterface.td | 3 ++-
mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir | 9 +++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Interfaces/LoopLikeInterface.td b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
index 5fb897339ffde..2dc17c8950e62 100644
--- a/mlir/include/mlir/Interfaces/LoopLikeInterface.td
+++ b/mlir/include/mlir/Interfaces/LoopLikeInterface.td
@@ -62,7 +62,8 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
/*args=*/(ins "::mlir::Value ":$value),
/*methodBody=*/"",
/*defaultImplementation=*/[{
- return !$_op->isAncestor(value.getParentRegion()->getParentOp());
+ ::mlir::Region *region = value.getParentRegion();
+ return !region || !$_op->isAncestor(region->getParentOp());
}]
>,
InterfaceMethod<[{
diff --git a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
index 94dfceadbc449..a0603dcf21dd2 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
@@ -583,3 +583,12 @@ module attributes {transform.with_named_sequence} {
transform.yield
}
}
+
+// CHECK32-LABEL: llvm.func @affine_for_index_bitwidth_32
+func.func @affine_for_index_bitwidth_32(%arg0: index, %arg1: index, %arg2: index, %arg3: index) {
+ %0 = affine.for %arg4 = 0 to 101 iter_args(%arg5 = %arg1) -> (index) {
+ affine.yield %arg3 : index
+ }
+ return
+}
+
More information about the Mlir-commits
mailing list