Skip to content

Commit 3c7381d

Browse files
committed
[AArch64][SME] Fix inlining bug introduced in llvm#78703
The issue didn't surface because the tests were not testing what they were supposed to test.
1 parent 6d981c1 commit 3c7381d

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,20 @@ static bool hasPossibleIncompatibleOps(const Function *F) {
233233

234234
bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
235235
const Function *Callee) const {
236-
SMEAttrs CallerAttrs(*Caller);
237-
SMEAttrs CalleeAttrs(*Callee);
236+
SMEAttrs CallerAttrs(*Caller), CalleeAttrs(*Callee);
237+
238+
// When inlining, we should consider the body of the function, not the
239+
// interface.
240+
if (CalleeAttrs.hasStreamingBody()) {
241+
CalleeAttrs.set(SMEAttrs::SM_Compatible, false);
242+
CalleeAttrs.set(SMEAttrs::SM_Enabled, true);
243+
}
244+
238245
if (CalleeAttrs.hasNewZABody())
239246
return false;
240247

241248
if (CallerAttrs.requiresLazySave(CalleeAttrs) ||
242-
(CallerAttrs.requiresSMChange(CalleeAttrs) &&
243-
(!CallerAttrs.hasStreamingInterfaceOrBody() ||
244-
!CalleeAttrs.hasStreamingBody()))) {
249+
CallerAttrs.requiresSMChange(CalleeAttrs)) {
245250
if (hasPossibleIncompatibleOps(Callee))
246251
return false;
247252
}
@@ -4062,4 +4067,4 @@ bool AArch64TTIImpl::shouldTreatInstructionLikeSelect(const Instruction *I) {
40624067
cast<BranchInst>(I->getNextNode())->isUnconditional())
40634068
return true;
40644069
return BaseT::shouldTreatInstructionLikeSelect(I);
4065-
}
4070+
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ entry:
137137
; [ ] N -> SC
138138
; [x] N -> N + B
139139
; [ ] N -> SC + B
140-
define i32 @normal_caller_locally_streaming_callee_inline() { ; FIXME: This is a bug, it shouldn't inline!
141-
; CHECK-LABEL: define i32 @normal_caller_locally_streaming_callee_inline
140+
define i32 @normal_caller_locally_streaming_callee_dont_inline() {
141+
; CHECK-LABEL: define i32 @normal_caller_locally_streaming_callee_dont_inline
142142
; CHECK-SAME: () #[[ATTR1]] {
143143
; CHECK-NEXT: entry:
144-
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
145-
; CHECK-NEXT: ret i32 [[RES_I]]
144+
; CHECK-NEXT: [[RES:%.*]] = call i32 @locally_streaming_callee()
145+
; CHECK-NEXT: ret i32 [[RES]]
146146
;
147147
entry:
148148
%res = call i32 @locally_streaming_callee()
@@ -154,12 +154,12 @@ entry:
154154
; [ ] N -> SC
155155
; [ ] N -> N + B
156156
; [x] N -> SC + B
157-
define i32 @normal_caller_streaming_compatible_locally_streaming_callee_inline() { ; FIXME: This is a bug, it shouldn't inline
158-
; CHECK-LABEL: define i32 @normal_caller_streaming_compatible_locally_streaming_callee_inline
157+
define i32 @normal_caller_streaming_compatible_locally_streaming_callee_dont_inline() {
158+
; CHECK-LABEL: define i32 @normal_caller_streaming_compatible_locally_streaming_callee_dont_inline
159159
; CHECK-SAME: () #[[ATTR1]] {
160160
; CHECK-NEXT: entry:
161-
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
162-
; CHECK-NEXT: ret i32 [[RES_I]]
161+
; CHECK-NEXT: [[RES:%.*]] = call i32 @streaming_compatible_locally_streaming_callee()
162+
; CHECK-NEXT: ret i32 [[RES]]
163163
;
164164
entry:
165165
%res = call i32 @streaming_compatible_locally_streaming_callee()
@@ -409,12 +409,12 @@ entry:
409409
; [ ] SC -> SC
410410
; [ ] SC -> N + B
411411
; [x] SC -> SC + B
412-
define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_inline() "aarch64_pstate_sm_compatible" { ; FIXME: This is a bug!
413-
; CHECK-LABEL: define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_inline
412+
define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_dont_inline() "aarch64_pstate_sm_compatible" {
413+
; CHECK-LABEL: define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_dont_inline
414414
; CHECK-SAME: () #[[ATTR0]] {
415415
; CHECK-NEXT: entry:
416-
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
417-
; CHECK-NEXT: ret i32 [[RES_I]]
416+
; CHECK-NEXT: [[RES:%.*]] = call i32 @streaming_compatible_locally_streaming_callee()
417+
; CHECK-NEXT: ret i32 [[RES]]
418418
;
419419
entry:
420420
%res = call i32 @streaming_compatible_locally_streaming_callee()

0 commit comments

Comments
 (0)