Skip to content

Commit 75805dc

Browse files
committed
[AArch64] Add implicit uses for operands when expanding BLR_RVMARKER.
Make sure we preserve info about passed arguments as implicit uses, to make sure later passes still have access to this information. This fixes a mis-compile where the machine-combiner would pick an incorrect free register.
1 parent e984c2b commit 75805dc

File tree

2 files changed

+105
-6
lines changed

2 files changed

+105
-6
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,10 @@ bool AArch64ExpandPseudo::expandCALL_RVMARKER(
673673
// Skip register arguments. Those are added during ISel, but are not
674674
// needed for the concrete branch.
675675
while (!MI.getOperand(RegMaskStartIdx).isRegMask()) {
676-
assert(MI.getOperand(RegMaskStartIdx).isReg() &&
677-
"should only skip register operands");
676+
auto MOP = MI.getOperand(RegMaskStartIdx);
677+
assert(MOP.isReg() && "can only add register operands");
678+
OriginalCall->addOperand(MachineOperand::CreateReg(
679+
MOP.getReg(), /*Def=*/false, /*Implicit=*/true));
678680
RegMaskStartIdx++;
679681
}
680682
for (; RegMaskStartIdx < MI.getNumOperands(); ++RegMaskStartIdx)
Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,118 @@
11
# RUN: llc -run-pass=aarch64-expand-pseudo -mtriple=arm64-apple-ios -o - -emit-call-site-info %s | FileCheck %s
22

3-
# CHECK-LABEL: test_1_callsite_info
4-
# CHECK: bb.0.entry:
3+
--- |
4+
define void @test_1_callsite_info() {
5+
ret void
6+
}
7+
8+
define void @test_bl_pass_x0_arg() {
9+
ret void
10+
}
11+
12+
define void @test_bl_pass_x0_x1_x2_args() {
13+
ret void
14+
}
15+
16+
define void @test_bl_pass_w0_w1_args() {
17+
ret void
18+
}
19+
20+
define void @test_blr_pass_w0_w1_args() {
21+
ret void
22+
}
23+
24+
define void @foo(i32 %a) {
25+
ret void
26+
}
27+
28+
...
29+
---
30+
31+
# CHECK-LABEL: : test_1_callsite_info
32+
# CHECK: bb.0:
533
# CHECK-NEXT: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def dead $x0, implicit-def $fp, implicit-def $w29, implicit $x0, implicit $sp, implicit $xzr, implicit $fp {
634
# CHECK-NEXT: BLR $x0, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
735
# CHECK-NEXT: ORRXrs $xzr, $fp, 0
836
# CHECK-NEXT: }
937
# CHECK-NEXT: RET undef $lr, implicit killed $w0
10-
---
38+
#
1139
name: test_1_callsite_info
1240
callSites:
1341
- {bb: 0, offset: 0, fwdArgRegs:
1442
- { arg: 0, reg: '$x0' } }
1543
body: |
16-
bb.0.entry:
44+
bb.0:
1745
liveins: $lr, $x0
1846
1947
BLR_RVMARKER $x0, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
2048
RET_ReallyLR implicit killed $w0
2149
...
50+
51+
# CHECK-LABEL: : test_bl_pass_x0_arg
52+
# CHECK: bb.0:
53+
# CHECK-NEXT: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def dead $x0, implicit-def $fp, implicit-def $w29, implicit $sp, implicit $x0, implicit $xzr, implicit $fp {
54+
# CHECK-NEXT: BL @foo, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
55+
# CHECK-NEXT: $fp = ORRXrs $xzr, $fp, 0
56+
# CHECK-NEXT: }
57+
# CHECK-NEXT: RET undef $lr, implicit killed $w0
58+
#
59+
name: test_bl_pass_x0_arg
60+
body: |
61+
bb.0:
62+
liveins: $lr, $x0
63+
64+
BLR_RVMARKER @foo, $x0, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
65+
RET_ReallyLR implicit killed $w0
66+
...
67+
68+
# CHECK-LABEL: : test_bl_pass_x0_x1_x2_args
69+
# CHECK: bb.0:
70+
# CHECK-NEXT: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def $x0, implicit-def $w0, implicit-def $fp, implicit-def $w29, implicit $sp, implicit $x0, implicit $x1, implicit $x2, implicit $xzr, implicit $fp {
71+
# CHECK-NEXT: BL @foo, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $x0, implicit $x1, implicit $x2, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def $x0
72+
# CHECK-NEXT: $fp = ORRXrs $xzr, $fp, 0
73+
# CHECK-NEXT: }
74+
# CHECK-NEXT: RET undef $lr
75+
#
76+
name: test_bl_pass_x0_x1_x2_args
77+
body: |
78+
bb.0:
79+
liveins: $lr, $x0, $x1, $x2
80+
81+
BLR_RVMARKER @foo, $x0, $x1, $x2, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def $x0
82+
RET_ReallyLR
83+
...
84+
85+
# CHECK-LABEL: : test_bl_pass_w0_w1_args
86+
# CHECK: bb.0:
87+
# CHECK-NEXT: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def dead $x0, implicit-def $fp, implicit-def $w29, implicit $sp, implicit $w0, implicit $w1, implicit $xzr, implicit $fp {
88+
# CHECK-NEXT: BL @foo, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $w0, implicit $w1, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
89+
# CHECK-NEXT: $fp = ORRXrs $xzr, $fp, 0
90+
# CHECK-NEXT: }
91+
# CHECK-NEXT: RET undef $lr, implicit killed $w0
92+
#
93+
name: test_bl_pass_w0_w1_args
94+
body: |
95+
bb.0:
96+
liveins: $lr, $w0, $w1
97+
98+
BLR_RVMARKER @foo, $w0, $w1, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
99+
RET_ReallyLR implicit killed $w0
100+
...
101+
102+
103+
# CHECK-LABEL: : test_blr_pass_w0_w1_args
104+
# CHECK: bb.0:
105+
# CHECK-NEXT: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit-def dead $x0, implicit-def $fp, implicit-def $w29, implicit $x8, implicit $sp, implicit $w0, implicit $w1, implicit $xzr, implicit $fp {
106+
# CHECK-NEXT: BLR $x8, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit $w0, implicit $w1, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
107+
# CHECK-NEXT: $fp = ORRXrs $xzr, $fp, 0
108+
# CHECK-NEXT: }
109+
# CHECK-NEXT: RET undef $lr, implicit killed $w0
110+
#
111+
name: test_blr_pass_w0_w1_args
112+
body: |
113+
bb.0:
114+
liveins: $lr, $x8, $w0, $w1
115+
116+
BLR_RVMARKER $x8, $w0, $w1, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
117+
RET_ReallyLR implicit killed $w0
118+
...

0 commit comments

Comments
 (0)