Skip to content

Commit

Permalink
[AArch64][SME] Fix inlining bug introduced in llvm#78703
Browse files Browse the repository at this point in the history
The issue didn't surface because the tests were not testing what
they were supposed to test.
  • Loading branch information
sdesmalen-arm committed Jan 30, 2024
1 parent 6d981c1 commit 3c7381d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
17 changes: 11 additions & 6 deletions llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,20 @@ static bool hasPossibleIncompatibleOps(const Function *F) {

bool AArch64TTIImpl::areInlineCompatible(const Function *Caller,
const Function *Callee) const {
SMEAttrs CallerAttrs(*Caller);
SMEAttrs CalleeAttrs(*Callee);
SMEAttrs CallerAttrs(*Caller), CalleeAttrs(*Callee);

// When inlining, we should consider the body of the function, not the
// interface.
if (CalleeAttrs.hasStreamingBody()) {
CalleeAttrs.set(SMEAttrs::SM_Compatible, false);
CalleeAttrs.set(SMEAttrs::SM_Enabled, true);
}

if (CalleeAttrs.hasNewZABody())
return false;

if (CallerAttrs.requiresLazySave(CalleeAttrs) ||
(CallerAttrs.requiresSMChange(CalleeAttrs) &&
(!CallerAttrs.hasStreamingInterfaceOrBody() ||
!CalleeAttrs.hasStreamingBody()))) {
CallerAttrs.requiresSMChange(CalleeAttrs)) {
if (hasPossibleIncompatibleOps(Callee))
return false;
}
Expand Down Expand Up @@ -4062,4 +4067,4 @@ bool AArch64TTIImpl::shouldTreatInstructionLikeSelect(const Instruction *I) {
cast<BranchInst>(I->getNextNode())->isUnconditional())
return true;
return BaseT::shouldTreatInstructionLikeSelect(I);
}
}
24 changes: 12 additions & 12 deletions llvm/test/Transforms/Inline/AArch64/sme-pstatesm-attrs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ entry:
; [ ] N -> SC
; [x] N -> N + B
; [ ] N -> SC + B
define i32 @normal_caller_locally_streaming_callee_inline() { ; FIXME: This is a bug, it shouldn't inline!
; CHECK-LABEL: define i32 @normal_caller_locally_streaming_callee_inline
define i32 @normal_caller_locally_streaming_callee_dont_inline() {
; CHECK-LABEL: define i32 @normal_caller_locally_streaming_callee_dont_inline
; CHECK-SAME: () #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
; CHECK-NEXT: ret i32 [[RES_I]]
; CHECK-NEXT: [[RES:%.*]] = call i32 @locally_streaming_callee()
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
%res = call i32 @locally_streaming_callee()
Expand All @@ -154,12 +154,12 @@ entry:
; [ ] N -> SC
; [ ] N -> N + B
; [x] N -> SC + B
define i32 @normal_caller_streaming_compatible_locally_streaming_callee_inline() { ; FIXME: This is a bug, it shouldn't inline
; CHECK-LABEL: define i32 @normal_caller_streaming_compatible_locally_streaming_callee_inline
define i32 @normal_caller_streaming_compatible_locally_streaming_callee_dont_inline() {
; CHECK-LABEL: define i32 @normal_caller_streaming_compatible_locally_streaming_callee_dont_inline
; CHECK-SAME: () #[[ATTR1]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
; CHECK-NEXT: ret i32 [[RES_I]]
; CHECK-NEXT: [[RES:%.*]] = call i32 @streaming_compatible_locally_streaming_callee()
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
%res = call i32 @streaming_compatible_locally_streaming_callee()
Expand Down Expand Up @@ -409,12 +409,12 @@ entry:
; [ ] SC -> SC
; [ ] SC -> N + B
; [x] SC -> SC + B
define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_inline() "aarch64_pstate_sm_compatible" { ; FIXME: This is a bug!
; CHECK-LABEL: define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_inline
define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_dont_inline() "aarch64_pstate_sm_compatible" {
; CHECK-LABEL: define i32 @streaming_compatible_caller_streaming_compatible_locally_streaming_callee_dont_inline
; CHECK-SAME: () #[[ATTR0]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[RES_I:%.*]] = call i32 @llvm.vscale.i32()
; CHECK-NEXT: ret i32 [[RES_I]]
; CHECK-NEXT: [[RES:%.*]] = call i32 @streaming_compatible_locally_streaming_callee()
; CHECK-NEXT: ret i32 [[RES]]
;
entry:
%res = call i32 @streaming_compatible_locally_streaming_callee()
Expand Down

0 comments on commit 3c7381d

Please sign in to comment.