llvm.org GIT mirror llvm / e0a85dd
[PartialInliner] Make PHIs free in cost computation. InlineCost also treats them as free and the current implementation can cause assertion failures if PHI nodes are moved outside the region from entry BBs to the region. It also updates the code to use the instructionsWithoutDebug iterator. Reviewers: davidxl, davide, vsk, graham-yiu-huawei Reviewed By: davidxl Differential Revision: https://reviews.llvm.org/D54748 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347683 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 9 months ago
2 changed file(s) with 49 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
833833 int PartialInlinerImpl::computeBBInlineCost(BasicBlock *BB) {
834834 int InlineCost = 0;
835835 const DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
836 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
837 if (isa(I))
838 continue;
839
840 switch (I->getOpcode()) {
836 for (Instruction &I : BB->instructionsWithoutDebug()) {
837 // Skip free instructions.
838 switch (I.getOpcode()) {
841839 case Instruction::BitCast:
842840 case Instruction::PtrToInt:
843841 case Instruction::IntToPtr:
844842 case Instruction::Alloca:
843 case Instruction::PHI:
845844 continue;
846845 case Instruction::GetElementPtr:
847 if (cast(I)->hasAllZeroIndices())
846 if (cast(&I)->hasAllZeroIndices())
848847 continue;
849848 break;
850849 default:
851850 break;
852851 }
853852
854 IntrinsicInst *IntrInst = dyn_cast(I);
853 IntrinsicInst *IntrInst = dyn_cast(&I);
855854 if (IntrInst) {
856855 if (IntrInst->getIntrinsicID() == Intrinsic::lifetime_start ||
857856 IntrInst->getIntrinsicID() == Intrinsic::lifetime_end)
858857 continue;
859858 }
860859
861 if (CallInst *CI = dyn_cast(I)) {
860 if (CallInst *CI = dyn_cast(&I)) {
862861 InlineCost += getCallsiteCost(CallSite(CI), DL);
863862 continue;
864863 }
865864
866 if (InvokeInst *II = dyn_cast(I)) {
865 if (InvokeInst *II = dyn_cast(&I)) {
867866 InlineCost += getCallsiteCost(CallSite(II), DL);
868867 continue;
869868 }
870869
871 if (SwitchInst *SI = dyn_cast(I)) {
870 if (SwitchInst *SI = dyn_cast(&I)) {
872871 InlineCost += (SI->getNumCases() + 1) * InlineConstants::InstrCost;
873872 continue;
874873 }
0 ; RUN: opt < %s -partial-inliner -S | FileCheck %s
1 ; RUN: opt < %s -passes=partial-inliner -S | FileCheck %s
2
3 ; Check that we do not overcompute the outlined region cost, where the PHIs in
4 ; the outlined region entry (BB4) are moved outside the region by CodeExtractor.
5
6 define i32 @bar(i32 %arg) {
7 bb:
8 %tmp = icmp slt i32 %arg, 0
9 br i1 %tmp, label %bb1, label %bb2
10
11 bb1:
12 br i1 undef, label %bb4, label %bb2
13
14 bb2: ; preds = %bb, %bb1
15 br i1 undef, label %bb4, label %bb5
16
17 bb4: ; preds = %bb1, %bb2
18 %xx1 = phi i32 [ 1, %bb1 ], [ 9, %bb2 ]
19 %xx2 = phi i32 [ 1, %bb1 ], [ 9, %bb2 ]
20 %xx3 = phi i32 [ 1, %bb1 ], [ 9, %bb2 ]
21 tail call void (...) @foo() #2
22 br label %bb5
23
24 bb5: ; preds = %bb4, %bb2
25 %tmp6 = phi i32 [ 1, %bb2 ], [ 9, %bb4 ]
26 ret i32 %tmp6
27 }
28
29 declare void @foo(...)
30
31 define i32 @dummy_caller(i32 %arg) {
32 bb:
33 ; CHECK-LABEL: @dummy_caller
34 ; CHECK: br i1
35 ; CHECK: br i1
36 ; CHECK: call void @bar.1.
37 %tmp = tail call i32 @bar(i32 %arg)
38 ret i32 %tmp
39 }