File tree Expand file tree Collapse file tree 3 files changed +41
-2
lines changed Expand file tree Collapse file tree 3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -713,9 +713,11 @@ bool Inliner::Impl::shouldInline(ResolvedCall &resolvedCall) {
713713 return false ;
714714
715715 // Don't allow inlining if the target is a self-recursive function.
716+ // Don't allow inlining if the call graph is like A->B->A.
716717 if (llvm::count_if (*resolvedCall.targetNode ,
717718 [&](CallGraphNode::Edge const &edge) -> bool {
718- return edge.getTarget () == resolvedCall.targetNode ;
719+ return edge.getTarget () == resolvedCall.targetNode ||
720+ edge.getTarget () == resolvedCall.sourceNode ;
719721 }) > 0 )
720722 return false ;
721723
Original file line number Diff line number Diff line change 1+ // RUN: mlir-opt %s -inline='default-pipeline=' | FileCheck %s
2+ // RUN: mlir-opt %s --mlir-disable-threading -inline='default-pipeline=' | FileCheck %s
3+
4+ module {
5+ // CHECK-LABEL: func.func @parent1
6+ func.func @parent1 (%arg0: i32 ) -> i32 {
7+ // CHECK: call @child
8+ %0 = call @child (%arg0 ) : (i32 ) -> i32
9+ return %0 : i32
10+ }
11+
12+ // CHECK-LABEL: func.func @parent2
13+ func.func @parent2 (%arg0: i32 ) -> i32 {
14+ // CHECK: call @child
15+ %0 = call @child (%arg0 ) : (i32 ) -> i32
16+ return %0 : i32
17+ }
18+
19+ // CHECK-LABEL: func.func @child
20+ func.func @child (%arg0: i32 ) -> i32 {
21+ %c10_i32 = arith.constant 10 : i32
22+ %c1_i32 = arith.constant 1 : i32
23+ %0 = arith.cmpi sge , %arg0 , %c10_i32 : i32
24+ %1 = scf.if %0 -> (i32 ) {
25+ scf.yield %arg0 : i32
26+ } else {
27+ %2 = arith.addi %arg0 , %c1_i32 : i32
28+ // CHECK: call @parent1
29+ // CHECK: call @parent2
30+ %3 = func.call @parent1 (%2 ) : (i32 ) -> i32
31+ %4 = func.call @parent2 (%2 ) : (i32 ) -> i32
32+ %5 = arith.addi %3 , %4 : i32
33+ scf.yield %5 : i32
34+ }
35+ return %1 : i32
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ func.func @foo0(%arg0 : i32) -> i32 {
1717
1818// CHECK-LABEL: func.func @foo1
1919func.func @foo1 (%arg0 : i32 ) -> i32 {
20- // CHECK: call @foo1
20+ // CHECK: call @foo0
2121 %0 = arith.constant 1 : i32
2222 %1 = arith.subi %arg0 , %0 : i32
2323 %2 = call @foo0 (%1 ) : (i32 ) -> i32
You can’t perform that action at this time.
0 commit comments