Skip to content

Commit ff68f71

Browse files
[mlir][builtin] Make unrealized_conversion_cast inlineable (#139722)
Until now, `builtin.unrealized_conversion_cast` ops could not be inlined by the Inliner pass.
1 parent 53e9d32 commit ff68f71

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

mlir/lib/Transforms/Utils/InliningUtils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "mlir/Transforms/InliningUtils.h"
1414

1515
#include "mlir/IR/Builders.h"
16+
#include "mlir/IR/BuiltinOps.h"
1617
#include "mlir/IR/IRMapping.h"
1718
#include "mlir/IR/Operation.h"
1819
#include "mlir/Interfaces/CallInterfaces.h"
@@ -182,6 +183,11 @@ static bool isLegalToInline(InlinerInterface &interface, Region *src,
182183
IRMapping &valueMapping) {
183184
for (auto &block : *src) {
184185
for (auto &op : block) {
186+
// UnrealizedConversionCastOp is inlineable but cannot implement the
187+
// inliner interface due to layering constraints.
188+
if (isa<UnrealizedConversionCastOp>(op))
189+
continue;
190+
185191
// Check this operation.
186192
if (!interface.isLegalToInline(&op, insertRegion,
187193
shouldCloneInlinedRegion, valueMapping)) {

mlir/test/Transforms/inlining.mlir

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
// RUN: mlir-opt %s -inline='op-pipelines=func.func(canonicalize,cse)' | FileCheck %s --check-prefix INLINE_SIMPLIFY
66

77
// Inline a function that takes an argument.
8-
func.func @func_with_arg(%c : i32) -> i32 {
9-
%b = arith.addi %c, %c : i32
10-
return %b : i32
8+
func.func @func_with_arg(%arg0 : i32) -> i32 {
9+
%b = arith.addi %arg0, %arg0 : i32
10+
%c = builtin.unrealized_conversion_cast %b : i32 to i64
11+
%d = builtin.unrealized_conversion_cast %c : i64 to i32
12+
return %d : i32
1113
}
1214

1315
// CHECK-LABEL: func @inline_with_arg
1416
func.func @inline_with_arg(%arg0 : i32) -> i32 {
1517
// CHECK-NEXT: arith.addi
18+
// CHECK-NEXT: unrealized_conversion_cast
19+
// CHECK-NEXT: unrealized_conversion_cast
1620
// CHECK-NEXT: return
1721

1822
%0 = call @func_with_arg(%arg0) : (i32) -> i32

0 commit comments

Comments
 (0)