llvm.org GIT mirror llvm / 60b50fa
[PartialInlining] Reduce outlining overhead by removing unneeded live-out(s) Differential Revision: http://reviews.llvm.org/D33694 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304375 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 2 years ago
3 changed file(s) with 146 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
651651 // only split block when necessary:
652652 PHINode *FirstPhi = getFirstPHI(PreReturn);
653653 unsigned NumPredsFromEntries = OI->ReturnBlockPreds.size();
654 auto IsTrivialPhi = [](PHINode *PN) -> Value * {
655 Value *CommonValue = PN->getIncomingValue(0);
656 if (all_of(PN->incoming_values(),
657 [&](Value *V) { return V == CommonValue; }))
658 return CommonValue;
659 return nullptr;
660 };
661
654662 if (FirstPhi && FirstPhi->getNumIncomingValues() > NumPredsFromEntries + 1) {
655663
656664 NewReturnBlock = NewReturnBlock->splitBasicBlock(
657665 NewReturnBlock->getFirstNonPHI()->getIterator());
658666 BasicBlock::iterator I = PreReturn->begin();
659667 Instruction *Ins = &NewReturnBlock->front();
668 SmallVector DeadPhis;
660669 while (I != PreReturn->end()) {
661670 PHINode *OldPhi = dyn_cast(I);
662671 if (!OldPhi)
673682 RetPhi->addIncoming(OldPhi->getIncomingValueForBlock(NewE), NewE);
674683 OldPhi->removeIncomingValue(NewE);
675684 }
685
686 // After incoming values splitting, the old phi may become trivial.
687 // Keeping the trivial phi can introduce definition inside the outline
688 // region which is live-out, causing necessary overhead (load, store
689 // arg passing etc).
690 if (auto *OldPhiVal = IsTrivialPhi(OldPhi)) {
691 OldPhi->replaceAllUsesWith(OldPhiVal);
692 DeadPhis.push_back(OldPhi);
693 }
694
676695 ++I;
677696 }
697
698 for (auto *DP : DeadPhis)
699 DP->eraseFromParent();
700
678701 for (auto E : OI->ReturnBlockPreds) {
679702 BasicBlock *NewE = cast(VMap[E]);
680703 NewE->getTerminator()->replaceUsesOfWith(PreReturn, NewReturnBlock);
0 ; RUN: opt -S -partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
1 ; RUN: opt -S -passes=partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
2 define i32 @test(i32 %arg) local_unnamed_addr #0 {
3 bb:
4 %tmp = tail call i32 (...) @bar() #1
5 %tmp1 = icmp slt i32 %arg, 0
6 br i1 %tmp1, label %bb6, label %bb2
7
8 bb2: ; preds = %bb
9 tail call void (...) @foo() #1
10 tail call void (...) @foo() #1
11 tail call void (...) @foo() #1
12 tail call void (...) @foo() #1
13 tail call void (...) @foo() #1
14 %tmp3 = tail call i32 (...) @bar() #1
15 %tmp4 = icmp eq i32 %tmp3, 10
16 br i1 %tmp4, label %bb6, label %bb5
17
18 bb5: ; preds = %bb2
19 tail call void (...) @foo() #1
20 tail call void (...) @foo() #1
21 tail call void (...) @foo() #1
22 tail call void (...) @foo() #1
23 br label %bb6
24
25 bb6: ; preds = %bb5, %bb2, %bb
26 %tmp7 = phi i32 [ %tmp, %bb5 ], [ 0, %bb ], [ %tmp, %bb2 ]
27 ret i32 %tmp7
28 }
29
30 declare i32 @bar(...) local_unnamed_addr #1
31
32 declare void @foo(...) local_unnamed_addr #1
33
34 ; Function Attrs: nounwind uwtable
35 define i32 @dummy_caller(i32 %arg) local_unnamed_addr #0 {
36 ; CHECK-LABEL: @dummy_caller
37 ; CHECK: codeRepl.i:
38 ; CHECK: call void @test.1_bb2()
39 ; CHECK-NOT: load
40 ; CHECK br
41
42 bb:
43 %tmp = tail call i32 @test(i32 %arg)
44 ret i32 %tmp
45 }
46
47 ; CHECK-LABEL: define internal void @test.1_bb2()
48 ; CHECK: .exitStub:
49 ; CHECK-NOT: store i32 %tmp7, i32* %tmp7.out
50 ; CHECK: ret
51
52
53 attributes #0 = { nounwind uwtable }
54 attributes #1 = { nounwind uwtable }
55
56 !llvm.module.flags = !{!0}
57 !llvm.ident = !{!1}
58
59 !0 = !{i32 1, !"wchar_size", i32 4}
60 !1 = !{!"clang version 5.0.0 (trunk 303574)"}
0 ; RUN: opt -S -partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
1 ; RUN: opt -S -passes=partial-inliner -max-num-inline-blocks=2 -skip-partial-inlining-cost-analysis < %s | FileCheck %s
2
3 define i32 @test(i32 %arg) local_unnamed_addr #0 {
4 bb:
5 %tmp = tail call i32 (...) @bar() #1
6 %tmp1 = icmp slt i32 %arg, 0
7 br i1 %tmp1, label %bb6, label %bb2
8
9 bb2: ; preds = %bb
10 tail call void (...) @foo() #1
11 tail call void (...) @foo() #1
12 tail call void (...) @foo() #1
13 tail call void (...) @foo() #1
14 tail call void (...) @foo() #1
15 %tmp3 = tail call i32 (...) @bar() #1
16 %tmp4 = icmp eq i32 %tmp3, 10
17 br i1 %tmp4, label %bb6, label %bb5
18
19 bb5: ; preds = %bb2
20 tail call void (...) @foo() #1
21 tail call void (...) @foo() #1
22 tail call void (...) @foo() #1
23 tail call void (...) @foo() #1
24 br label %bb6
25
26 bb6: ; preds = %bb5, %bb2, %bb
27 %tmp7 = phi i32 [ 1, %bb5 ], [ 0, %bb ], [ 1, %bb2 ]
28 ret i32 %tmp7
29 }
30
31 ; Function Attrs: nounwind uwtable
32 declare i32 @bar(...) local_unnamed_addr #0
33
34 ; Function Attrs: nounwind uwtable
35 declare void @foo(...) local_unnamed_addr #0
36
37 ; Function Attrs: nounwind uwtable
38 define i32 @dummy_caller(i32 %arg) local_unnamed_addr #0 {
39 ; CHECK-LABEL: @dummy_caller
40 ; CHECK: codeRepl.i:
41 ; CHECK: call void @test.1_bb2()
42 ; CHECK-NOT: load
43 ; CHECK br
44 bb:
45 %tmp = tail call i32 @test(i32 %arg)
46 ret i32 %tmp
47 }
48
49 ; CHECK-LABEL: define internal void @test.1_bb2()
50 ; CHECK: .exitStub:
51 ; CHECK-NOT: store i32 %tmp7, i32* %tmp7.out
52 ; CHECK: ret
53
54 attributes #0 = { nounwind uwtable }
55 attributes #1 = { nounwind }
56
57 !llvm.module.flags = !{!0}
58 !llvm.ident = !{!1}
59
60 !0 = !{i32 1, !"wchar_size", i32 4}
61 !1 = !{!"clang version 5.0.0 (trunk 303574)"}