Skip to content

Commit fb470db

Browse files
[AArch64] Avoid inlining if ZT0 needs preserving. (#101343)
Inlining may result in different behaviour when the callee clobbers ZT0, because normally the call-site will have code to preserve ZT0. When inlining the function this code to preserve ZT0 will no longer be emitted, and so the resulting behaviour of the program is changed.
1 parent a6a462f commit fb470db

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
254254
return false;
255255

256256
if (CallerAttrs.requiresLazySave(CalleeAttrs) ||
257-
CallerAttrs.requiresSMChange(CalleeAttrs)) {
257+
CallerAttrs.requiresSMChange(CalleeAttrs) ||
258+
CallerAttrs.requiresPreservingZT0(CalleeAttrs)) {
258259
if (hasPossibleIncompatibleOps(Callee))
259260
return false;
260261
}

llvm/test/Transforms/Inline/AArch64/sme-pstateza-attrs.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,51 @@ define void @shared_za_caller_private_za_callee_call_tpidr2_restore_dont_inline(
231231
ret void
232232
}
233233

234+
define void @nonzt0_callee() {
235+
; CHECK-LABEL: define void @nonzt0_callee
236+
; CHECK-SAME: () #[[ATTR0]] {
237+
; CHECK-NEXT: call void asm sideeffect "
238+
; CHECK-NEXT: call void @inlined_body()
239+
; CHECK-NEXT: ret void
240+
;
241+
call void asm sideeffect "; inlineasm", ""()
242+
call void @inlined_body()
243+
ret void
244+
}
245+
246+
define void @shared_zt0_caller_nonzt0_callee_dont_inline() "aarch64_inout_zt0" {
247+
; CHECK-LABEL: define void @shared_zt0_caller_nonzt0_callee_dont_inline
248+
; CHECK-SAME: () #[[ATTR3:[0-9]+]] {
249+
; CHECK-NEXT: call void @nonzt0_callee()
250+
; CHECK-NEXT: ret void
251+
;
252+
call void @nonzt0_callee()
253+
ret void
254+
}
255+
256+
define void @shared_zt0_callee() "aarch64_inout_zt0" {
257+
; CHECK-LABEL: define void @shared_zt0_callee
258+
; CHECK-SAME: () #[[ATTR3]] {
259+
; CHECK-NEXT: call void asm sideeffect "
260+
; CHECK-NEXT: call void @inlined_body()
261+
; CHECK-NEXT: ret void
262+
;
263+
call void asm sideeffect "; inlineasm", ""()
264+
call void @inlined_body()
265+
ret void
266+
}
267+
268+
define void @shared_zt0_caller_shared_zt0_callee_inline() "aarch64_inout_zt0" {
269+
; CHECK-LABEL: define void @shared_zt0_caller_shared_zt0_callee_inline
270+
; CHECK-SAME: () #[[ATTR3]] {
271+
; CHECK-NEXT: call void asm sideeffect "
272+
; CHECK-NEXT: call void @inlined_body()
273+
; CHECK-NEXT: ret void
274+
;
275+
call void @shared_zt0_callee()
276+
ret void
277+
}
278+
234279
declare void @__arm_za_disable()
235280
declare void @__arm_tpidr2_save()
236281
declare void @__arm_tpidr2_restore(ptr)

0 commit comments

Comments
 (0)