Skip to content

Commit

Permalink
[AlwaysInliner] Emit inline remark only when successful
Browse files Browse the repository at this point in the history
Failures in `InlineFunction()` are caught after D121722, but `emitInlinedIntoBasedOnCost()` should only be called when inlining is successful. This also removes an unnecessary call to `shouldInline()` which always returned `InlineCost::getAlways()`.

Reviewed By: kyulee, nikic

Differential Revision: https://reviews.llvm.org/D121946
  • Loading branch information
ellishg committed Mar 17, 2022
1 parent 187a5f2 commit f6b5142
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
14 changes: 5 additions & 9 deletions llvm/lib/Transforms/IPO/AlwaysInliner.cpp
Expand Up @@ -68,17 +68,8 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
for (CallBase *CB : Calls) {
Function *Caller = CB->getCaller();
OptimizationRemarkEmitter ORE(Caller);
auto OIC = shouldInline(
*CB,
[&](CallBase &CB) {
return InlineCost::getAlways("always inline attribute");
},
ORE);
assert(OIC);
DebugLoc DLoc = CB->getDebugLoc();
BasicBlock *Block = CB->getParent();
emitInlinedIntoBasedOnCost(ORE, DLoc, Block, F, *Caller, *OIC, false,
DEBUG_TYPE);

InlineFunctionInfo IFI(
/*cg=*/nullptr, GetAssumptionCache, &PSI,
Expand All @@ -98,6 +89,11 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
continue;
}

emitInlinedIntoBasedOnCost(
ORE, DLoc, Block, F, *Caller,
InlineCost::getAlways("always inline attribute"),
/*ForProfileContext=*/false, DEBUG_TYPE);

// Merge the attributes based on the inlining.
AttributeFuncs::mergeAttributesForInlining(*Caller, F);

Expand Down
8 changes: 5 additions & 3 deletions llvm/test/Transforms/Inline/always-inline-remark.ll
@@ -1,4 +1,4 @@
; RUN: opt -passes="always-inline" -pass-remarks-missed=inline -S < %s 2>&1 | FileCheck %s
; RUN: opt -passes="always-inline" -pass-remarks=inline -pass-remarks-missed=inline -S < %s 2>&1 | FileCheck %s --implicit-check-not="remark: "

declare void @personalityFn1();
declare void @personalityFn2();
Expand All @@ -12,9 +12,11 @@ define void @bar() alwaysinline personality void ()* @personalityFn1 {
}

define void @goo() personality void ()* @personalityFn2 {
; CHECK-DAG: 'bar' is not inlined into 'goo': incompatible personality
; CHECK-DAG: remark: {{.*}}: 'bar' is not inlined into 'goo': incompatible personality
call void @bar()
; CHECK-DAG: 'foo' is not inlined into 'goo': unsupported operand bundle
; CHECK-DAG: remark: {{.*}}: 'foo' is not inlined into 'goo': unsupported operand bundle
call void @foo() [ "CUSTOM_OPERAND_BUNDLE"() ]
; CHECK-DAG: remark: {{.*}}: 'foo' inlined into 'goo' with (cost=always): always inline attribute
call void @foo()
ret void
}

0 comments on commit f6b5142

Please sign in to comment.