[llvm] 84c6689 - [AlwaysInliner] Check inliner errors even without assserts
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 17 10:16:28 PDT 2022
Author: Ellis Hoag
Date: 2022-03-17T10:16:23-07:00
New Revision: 84c6689b1511cc7bcad8f9f166bdc9808b8cdac8
URL: https://github.com/llvm/llvm-project/commit/84c6689b1511cc7bcad8f9f166bdc9808b8cdac8
DIFF: https://github.com/llvm/llvm-project/commit/84c6689b1511cc7bcad8f9f166bdc9808b8cdac8.diff
LOG: [AlwaysInliner] Check inliner errors even without assserts
When we build clang without asserts we should still check the result of
`InlineFunction()` to be sure there wasn't an error. Otherwise we could
incorrectly merge attributes in the next line.
This also removes a redundent call to `getCaller()`.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D121722
Added:
llvm/test/Transforms/Inline/always-inline-remark.ll
Modified:
llvm/lib/Transforms/IPO/AlwaysInliner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
index cf81cc8202c7b..c7889a26e3058 100644
--- a/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
+++ b/llvm/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -75,18 +75,28 @@ PreservedAnalyses AlwaysInlinerPass::run(Module &M,
},
ORE);
assert(OIC);
- emitInlinedIntoBasedOnCost(ORE, CB->getDebugLoc(), CB->getParent(), F,
- *Caller, *OIC, false, DEBUG_TYPE);
+ DebugLoc DLoc = CB->getDebugLoc();
+ BasicBlock *Block = CB->getParent();
+ emitInlinedIntoBasedOnCost(ORE, DLoc, Block, F, *Caller, *OIC, false,
+ DEBUG_TYPE);
InlineFunctionInfo IFI(
/*cg=*/nullptr, GetAssumptionCache, &PSI,
- &FAM.getResult<BlockFrequencyAnalysis>(*(CB->getCaller())),
+ &FAM.getResult<BlockFrequencyAnalysis>(*Caller),
&FAM.getResult<BlockFrequencyAnalysis>(F));
InlineResult Res = InlineFunction(
*CB, IFI, &FAM.getResult<AAManager>(F), InsertLifetime);
- assert(Res.isSuccess() && "unexpected failure to inline");
- (void)Res;
+ if (!Res.isSuccess()) {
+ ORE.emit([&]() {
+ return OptimizationRemarkMissed(DEBUG_TYPE, "NotInlined", DLoc,
+ Block)
+ << "'" << ore::NV("Callee", &F) << "' is not inlined into '"
+ << ore::NV("Caller", Caller)
+ << "': " << ore::NV("Reason", Res.getFailureReason());
+ });
+ continue;
+ }
// Merge the attributes based on the inlining.
AttributeFuncs::mergeAttributesForInlining(*Caller, F);
diff --git a/llvm/test/Transforms/Inline/always-inline-remark.ll b/llvm/test/Transforms/Inline/always-inline-remark.ll
new file mode 100644
index 0000000000000..294a00936878a
--- /dev/null
+++ b/llvm/test/Transforms/Inline/always-inline-remark.ll
@@ -0,0 +1,20 @@
+; RUN: opt -passes="always-inline" -pass-remarks-missed=inline -S < %s 2>&1 | FileCheck %s
+
+declare void @personalityFn1();
+declare void @personalityFn2();
+
+define void @foo() alwaysinline {
+ ret void
+}
+
+define void @bar() alwaysinline personality void ()* @personalityFn1 {
+ ret void
+}
+
+define void @goo() personality void ()* @personalityFn2 {
+ ; CHECK-DAG: 'bar' is not inlined into 'goo': incompatible personality
+ call void @bar()
+ ; CHECK-DAG: 'foo' is not inlined into 'goo': unsupported operand bundle
+ call void @foo() [ "CUSTOM_OPERAND_BUNDLE"() ]
+ ret void
+}
More information about the llvm-commits
mailing list