Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ Makes programs 10x faster by doing Special New Thing.
corresponding metadata) now apply only at the point of definition, instead of
for the execution of the function (for arguments) or forever (for returns).

* `alwaysinline` no longer bypasses inlining compatibility checks based on
target features. Inlining will only be performed if it is safe to do so.

### Changes to LLVM infrastructure

* Removed ``Constant::isZeroValue``. It was functionally identical to
Expand Down
16 changes: 10 additions & 6 deletions llvm/lib/Analysis/InlineCost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,16 +3081,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);
}
Expand Down Expand Up @@ -3213,6 +3211,13 @@ std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
" address space");
}

// Inlining into a function with less target features is unsound, so enforce
// this even if alwaysinline is used.
Function *Caller = Call.getCaller();
if (!IgnoreTTIInlineCompatible &&
!CalleeTTI.areInlineCompatible(Caller, Callee))
return InlineResult::failure("conflicting target features");

// Calls to functions with always-inline attributes should be inlined
// whenever possible.
if (Call.hasFnAttr(Attribute::AlwaysInline)) {
Expand All @@ -3227,8 +3232,7 @@ 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))
if (!functionsHaveCompatibleAttributes(Caller, Callee, GetTLI))
return InlineResult::failure("conflicting attributes");

// Flatten: inline all viable calls from flatten functions regardless of cost.
Expand Down
32 changes: 32 additions & 0 deletions llvm/test/Transforms/Inline/X86/always-inline-features.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -S -passes=inline < %s | FileCheck %s

target triple = "x86_64-unknown-linux-gnu"

; Even with alwaysinline, the callee cannot be inlined, because the target
; features are incompatible. Inlining it would result in a selection failure
; crash.

define <16 x float> @caller(<16 x float> %a, <16 x float> %b) {
; CHECK-LABEL: define <16 x float> @caller(
; CHECK-SAME: <16 x float> [[A:%.*]], <16 x float> [[B:%.*]]) {
; CHECK-NEXT: [[RES:%.*]] = call <16 x float> @callee(<16 x float> [[A]], <16 x float> [[B]]) #[[ATTR2:[0-9]+]]
; CHECK-NEXT: ret <16 x float> [[RES]]
;
%res = call <16 x float> @callee(<16 x float> %a, <16 x float> %b) alwaysinline
ret <16 x float> %res
}

define <16 x float> @callee(<16 x float> %a, <16 x float> %b) #0 {
; CHECK-LABEL: define <16 x float> @callee(
; CHECK-SAME: <16 x float> [[A:%.*]], <16 x float> [[B:%.*]]) #[[ATTR0:[0-9]+]] {
; CHECK-NEXT: [[RES:%.*]] = call <16 x float> @llvm.x86.avx512.min.ps.512(<16 x float> [[A]], <16 x float> [[B]], i32 0)
; CHECK-NEXT: ret <16 x float> [[RES]]
;
%res = call <16 x float> @llvm.x86.avx512.min.ps.512(<16 x float> %a, <16 x float> %b, i32 0)
ret <16 x float> %res
}

declare <16 x float> @llvm.x86.avx512.min.ps.512(<16 x float>, <16 x float>, i32 immarg)

attributes #0 = { "target-features"="+avx512bw,+avx512dq,+avx512f" }
Loading