Skip to content

Commit 658e476

Browse files
[AArch64] Fix wrong condition in canUseAsPrologue (#81878)
Inline stack probing code may need a scratch register, hence basic blocks where such register is not available cannot be used as prologues. Checking for an available scratch regidster was incorrectly skipped when the function uses stack probing.
1 parent 232a14d commit 658e476

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ bool AArch64FrameLowering::canUseAsPrologue(
10631063

10641064
// Don't need a scratch register if we're not going to re-align the stack or
10651065
// emit stack probes.
1066-
if (!RegInfo->hasStackRealignment(*MF) && TLI->hasInlineStackProbe(*MF))
1066+
if (!RegInfo->hasStackRealignment(*MF) && !TLI->hasInlineStackProbe(*MF))
10671067
return true;
10681068
// Otherwise, we can use any block as long as it has a scratch register
10691069
// available.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 4
2+
# RUN: llc %s --start-before=shrink-wrap -stop-after=prologepilog -o - | FileCheck %s
3+
--- |
4+
target triple = "aarch64-linux"
5+
6+
define void @f(i32 %n) #0 {
7+
entry:
8+
%a = alloca i8, i32 150000, align 8
9+
%c0 = icmp sle i32 %n, 1
10+
br i1 %c0, label %if.then1, label %exit
11+
12+
if.then1:
13+
call void @g(ptr %a)
14+
br label %exit
15+
16+
exit:
17+
ret void
18+
}
19+
20+
declare void @g(...)
21+
22+
attributes #0 = { nounwind "probe-stack"="inline-asm" "stack-probe-size"="4096" }
23+
24+
...
25+
---
26+
name: f
27+
alignment: 4
28+
tracksRegLiveness: true
29+
liveins:
30+
- { reg: '$w0', virtual-reg: '' }
31+
frameInfo:
32+
localFrameSize: 150000
33+
stack:
34+
- { id: 0, name: a, type: default, offset: 0, size: 150000, alignment: 8,
35+
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
36+
local-offset: -150000, debug-info-variable: '', debug-info-expression: '',
37+
debug-info-location: '' }
38+
entry_values: []
39+
callSites: []
40+
debugValueSubstitutions: []
41+
constants: []
42+
machineFunctionInfo: {}
43+
body: |
44+
; CHECK-LABEL: name: f
45+
; CHECK: bb.0.entry:
46+
; CHECK-NEXT: successors: %bb.3(0x80000000)
47+
; CHECK-NEXT: liveins: $w0, $lr
48+
; CHECK-NEXT: {{ $}}
49+
; CHECK-NEXT: early-clobber $sp = frame-setup STPXpre killed $fp, killed $lr, $sp, -2 :: (store (s64) into %stack.2), (store (s64) into %stack.1)
50+
; CHECK-NEXT: $x9 = frame-setup SUBXri $sp, 36, 12
51+
; CHECK-NEXT: {{ $}}
52+
; CHECK-NEXT: bb.3.entry:
53+
; CHECK-NEXT: successors: %bb.4(0x40000000), %bb.3(0x40000000)
54+
; CHECK-NEXT: liveins: $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x25, $x27, $x28
55+
; CHECK-NEXT: {{ $}}
56+
; CHECK-NEXT: $sp = frame-setup SUBXri $sp, 1, 12
57+
; CHECK-NEXT: frame-setup STRXui $xzr, $sp, 0
58+
; CHECK-NEXT: $xzr = frame-setup SUBSXrx64 $sp, $x9, 24, implicit-def $nzcv
59+
; CHECK-NEXT: frame-setup Bcc 1, %bb.3, implicit $nzcv
60+
; CHECK-NEXT: {{ $}}
61+
; CHECK-NEXT: bb.4.entry:
62+
; CHECK-NEXT: successors: %bb.1(0x40000000), %bb.2(0x40000000)
63+
; CHECK-NEXT: liveins: $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x25, $x27, $x28
64+
; CHECK-NEXT: {{ $}}
65+
; CHECK-NEXT: $sp = frame-setup SUBXri $sp, 2544, 0
66+
; CHECK-NEXT: frame-setup STRXui $xzr, $sp, 0
67+
; CHECK-NEXT: $x9 = IMPLICIT_DEF
68+
; CHECK-NEXT: dead $wzr = SUBSWri killed renamable $w0, 1, 0, implicit-def $nzcv
69+
; CHECK-NEXT: Bcc 12, %bb.2, implicit $nzcv
70+
; CHECK-NEXT: B %bb.1
71+
; CHECK-NEXT: {{ $}}
72+
; CHECK-NEXT: bb.1.if.then1:
73+
; CHECK-NEXT: successors: %bb.2(0x80000000)
74+
; CHECK-NEXT: liveins: $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x23, $x25, $x25, $x27, $x28
75+
; CHECK-NEXT: {{ $}}
76+
; CHECK-NEXT: $x0 = ADDXri $sp, 0, 0
77+
; CHECK-NEXT: BL @g, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit-def $sp
78+
; CHECK-NEXT: {{ $}}
79+
; CHECK-NEXT: bb.2.exit:
80+
; CHECK-NEXT: $sp = frame-destroy ADDXri $sp, 36, 12
81+
; CHECK-NEXT: $sp = frame-destroy ADDXri $sp, 2544, 0
82+
; CHECK-NEXT: early-clobber $sp, $fp, $lr = frame-destroy LDPXpost $sp, 2 :: (load (s64) from %stack.2), (load (s64) from %stack.1)
83+
; CHECK-NEXT: RET_ReallyLR
84+
bb.0.entry:
85+
successors: %bb.1(0x40000000), %bb.2(0x40000000)
86+
liveins: $w0
87+
88+
$x9 = IMPLICIT_DEF
89+
dead $wzr = SUBSWri killed renamable $w0, 1, 0, implicit-def $nzcv
90+
Bcc 12, %bb.2, implicit $nzcv
91+
B %bb.1
92+
93+
bb.1.if.then1:
94+
successors: %bb.2(0x80000000)
95+
liveins: $x0, $x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x23, $x25, $x25, $x27, $x28
96+
97+
ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
98+
$x0 = ADDXri %stack.0.a, 0, 0
99+
BL @g, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit-def $sp
100+
ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
101+
102+
bb.2.exit:
103+
RET_ReallyLR
104+
105+
...

0 commit comments

Comments
 (0)