diff options
author | Kazu Hirata <kazu@google.com> | 2023-06-02 16:00:47 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2023-06-02 16:00:47 -0700 |
commit | d6f994acb3d545b80161e24ab742c9c69d4bbf33 (patch) | |
tree | 6978c952a123b1fdc4ff417dc15ce9f12945a0cb /llvm/lib/Analysis/InlineCost.cpp | |
parent | 14c44dfbcf1d6f81c1cdaa90ed243b3d53147903 (diff) | |
download | llvm-d6f994acb3d545b80161e24ab742c9c69d4bbf33.zip llvm-d6f994acb3d545b80161e24ab742c9c69d4bbf33.tar.gz llvm-d6f994acb3d545b80161e24ab742c9c69d4bbf33.tar.bz2 |
[InlineCost] Check for conflicting target attributes early
When we inline a callee into a caller, the compiler needs to make sure
that the caller supports a superset of instruction sets that the
callee is allowed to use. Normally, we check for the compatibility of
target features via functionsHaveCompatibleAttributes, but that
happens after we decide to honor call site attribute
Attribute::AlwaysInline. If the caller contains a call marked with
Attribute::AlwaysInline, which can happen with
__attribute__((flatten)) placed on the caller, the caller could end up
with code that cannot be lowered to assembly code.
This patch fixes the problem by checking the target feature
compatibility before we honor Attribute::AlwaysInline.
Fixes https://github.com/llvm/llvm-project/issues/62664
Differential Revision: https://reviews.llvm.org/D150396
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index 02871aa..baf4185 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -2801,16 +2801,14 @@ LLVM_DUMP_METHOD void InlineCostCallAnalyzer::dump() { print(dbgs()); } /// Test that there are no attribute conflicts between Caller and Callee /// that prevent inlining. static bool functionsHaveCompatibleAttributes( - Function *Caller, Function *Callee, TargetTransformInfo &TTI, + Function *Caller, Function *Callee, function_ref<const TargetLibraryInfo &(Function &)> &GetTLI) { // Note that CalleeTLI must be a copy not a reference. The legacy pass manager // caches the most recently created TLI in the TargetLibraryInfoWrapperPass // object, and always returns the same object (which is overwritten on each // GetTLI call). Therefore we copy the first result. auto CalleeTLI = GetTLI(*Callee); - return (IgnoreTTIInlineCompatible || - TTI.areInlineCompatible(Caller, Callee)) && - GetTLI(*Caller).areInlineCompatible(CalleeTLI, + return GetTLI(*Caller).areInlineCompatible(CalleeTLI, InlineCallerSupersetNoBuiltin) && AttributeFuncs::areInlineCompatible(*Caller, *Callee); } @@ -2926,6 +2924,12 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision( " address space"); } + // Never inline functions with conflicting target attributes. + Function *Caller = Call.getCaller(); + if (!IgnoreTTIInlineCompatible && + !CalleeTTI.areInlineCompatible(Caller, Callee)) + return InlineResult::failure("conflicting target attributes"); + // Calls to functions with always-inline attributes should be inlined // whenever possible. if (Call.hasFnAttr(Attribute::AlwaysInline)) { @@ -2940,8 +2944,12 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision( // Never inline functions with conflicting attributes (unless callee has // always-inline attribute). - Function *Caller = Call.getCaller(); - if (!functionsHaveCompatibleAttributes(Caller, Callee, CalleeTTI, GetTLI)) + // FIXME: functionsHaveCompatibleAttributes below checks for compatibilities + // of different kinds of function attributes -- sanitizer-related ones, + // checkDenormMode, no-builtin-memcpy, etc. It's unclear if we really want + // the always-inline attribute to take precedence over these different types + // of function attributes. + if (!functionsHaveCompatibleAttributes(Caller, Callee, GetTLI)) return InlineResult::failure("conflicting attributes"); // Don't inline this call if the caller has the optnone attribute. |