Skip to content

Commit 28d3623

Browse files
committed
[mlir] [nfc] fix crash when scf utils work on llvm.func
fixed #119378
1 parent bd261ec commit 28d3623

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

mlir/lib/Dialect/SCF/Utils/Utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ FailureOr<func::FuncOp> mlir::outlineSingleBlockRegion(RewriterBase &rewriter,
130130

131131
// Outline before current function.
132132
OpBuilder::InsertionGuard g(rewriter);
133-
rewriter.setInsertionPoint(region.getParentOfType<func::FuncOp>());
133+
rewriter.setInsertionPoint(region.getParentOfType<FunctionOpInterface>());
134134

135135
SetVector<Value> captures;
136136
getUsedValuesDefinedAbove(region, captures);

mlir/test/Transforms/scf-if-utils.mlir

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,15 @@ func.func @outline_empty_if_else(%cond: i1, %a: index, %b: memref<?xf32>, %c: i8
7373
}
7474
return
7575
}
76+
77+
// -----
78+
79+
// This test checks scf utils can work on llvm func.
80+
// CHECK-LABEL: @llvm_func
81+
llvm.func @llvm_func(%cond: i1, %a: i32) {
82+
scf.if %cond {
83+
} else {
84+
"some_op"(%cond, %a) : (i1, i32) -> ()
85+
}
86+
llvm.return
87+
}

mlir/test/lib/Dialect/SCF/TestSCFUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ struct TestSCFIfUtilsPass
7979
StringRef getDescription() const final { return "test scf.if utils"; }
8080
explicit TestSCFIfUtilsPass() = default;
8181

82+
void getDependentDialects(DialectRegistry &registry) const override {
83+
registry.insert<func::FuncDialect>();
84+
}
85+
8286
void runOnOperation() override {
8387
int count = 0;
8488
getOperation().walk([&](scf::IfOp ifOp) {

0 commit comments

Comments
 (0)