[llvm-branch-commits] [llvm] 705f593 - [AArch64] Restore always-inline behaviour for incompatible SME attributes.
Tobias Hieta via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 12 07:55:50 PDT 2026
Author: Sander de Smalen
Date: 2026-10-12T16:55:15+02:00
New Revision: 705f593fb506a9eef82d530a5a54c9b8ac6b1099
URL: https://github.com/llvm/llvm-project/commit/705f593fb506a9eef82d530a5a54c9b8ac6b1099
DIFF: https://github.com/llvm/llvm-project/commit/705f593fb506a9eef82d530a5a54c9b8ac6b1099.diff
LOG: [AArch64] Restore always-inline behaviour for incompatible SME attributes.
PR #209345 changed inlining behaviour for 'alwaysinline' functions
when the callee's SME attributes were incompatible with the caller's
SME attributes. This is not desirable, as it would stop small utility
routines being inlined into streaming functions (such as std::max).
This PR restores the original behaviour from before #209345.
For LLVM 24 we intend to solve this in a better way, see #223393.
This addresses https://github.com/llvm/llvm-project/issues/217639
Added:
Modified:
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
llvm/test/Transforms/Inline/AArch64/sme-always-inline.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 209bd30de9ff9..66af547fc279d 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -300,7 +300,17 @@ bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
if (CallAttrs.requiresLazySave() || CallAttrs.requiresSMChange() ||
CallAttrs.requiresPreservingZT0() ||
CallAttrs.requiresPreservingAllZAState()) {
- if (hasPossibleIncompatibleOps(Callee, *getTLI()))
+ // For always-inline functions we don't check the SME attributes as
+ // otherwise it would block simple 'alwaysinline' utility functions in
+ // existing libraries from being inlined in streaming functions (e.g.
+ // std::max). Clang issues a warning diagnostic for this case to warn the
+ // user that always-inlining the function may not be safe. Unfortunately, it
+ // is
diff icult to comprehensively guard against this in Clang, as it would
+ // require analyzing the function bodies for all always-inline functions
+ // for each of their call-sites. The approach taken here is therefore a
+ // compromise between safety and usability.
+ if (!Callee->hasFnAttribute(Attribute::AlwaysInline) &&
+ hasPossibleIncompatibleOps(Callee, *getTLI()))
return false;
}
diff --git a/llvm/test/Transforms/Inline/AArch64/sme-always-inline.ll b/llvm/test/Transforms/Inline/AArch64/sme-always-inline.ll
index 0a5749a233813..94bfe133bdbc4 100644
--- a/llvm/test/Transforms/Inline/AArch64/sme-always-inline.ll
+++ b/llvm/test/Transforms/Inline/AArch64/sme-always-inline.ll
@@ -1,27 +1,21 @@
-; REQUIRES: aarch64-registered-target
; RUN: opt -passes=always-inline -S < %s | FileCheck %s
target triple = "aarch64"
-define internal float @callee(float %v) #0 {
-; CHECK-LABEL: define internal float @callee(
-; CHECK-SAME: float [[V:%.*]]) #[[ATTR0:[0-9]+]] {
-; CHECK-NEXT: [[RES:%.*]] = tail call float @llvm.sin.f32(float [[V]])
-; CHECK-NEXT: ret float [[RES]]
-;
+define internal float @callee(float %v) "target-features"="+sme2" alwaysinline {
+; CHECK-NOT: define internal float @callee
%res = tail call float @llvm.sin.f32(float %v)
ret float %res
}
-define float @caller(float %v) #1 {
+; Test that the body of @callee is inlined due to it's `alwaysinline` attribute,
+; despite having mismatching streaming attributes.
+define float @caller(float %v) "target-features"="+sme2" "aarch64_pstate_sm_enabled" {
; CHECK-LABEL: define float @caller(
-; CHECK-SAME: float [[V:%.*]]) #[[ATTR1:[0-9]+]] {
-; CHECK-NEXT: [[RES:%.*]] = call float @callee(float [[V]])
+; CHECK-SAME: float [[V:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[RES:%.*]] = call float @llvm.sin.f32(float [[V]])
; CHECK-NEXT: ret float [[RES]]
;
%res = call float @callee(float %v)
ret float %res
}
-
-attributes #0 = { "target-features"="+sme2" nounwind alwaysinline }
-attributes #1 = { "target-features"="+sme2" nounwind "aarch64_pstate_sm_enabled" }
More information about the llvm-branch-commits
mailing list