[AlwaysInliner] Emit inline remark only when successful

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
This commit is contained in:
Ellis Hoag 2022-03-17 13:00:27 -07:00
parent 187a5f230f
commit f6b5142ac2
2 changed files with 10 additions and 12 deletions

View File

@ -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,
@ -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);

View File

@ -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();
@ -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
}