Skip to content

Commit 8fb2113

Browse files
authored
[AArch64] Preserve undef on registers when expanding CALL_RVMARKER. (#71177)
Preserve the undef flag on register operands when expanding CALL_RVMARKER. This fixes a crash when the x0 operand is undef, e.g. because it was poison in the input IR. Fixes #68005.
1 parent 93b8f56 commit 8fb2113

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ bool AArch64ExpandPseudo::expandCALL_RVMARKER(
794794
auto MOP = MI.getOperand(RegMaskStartIdx);
795795
assert(MOP.isReg() && "can only add register operands");
796796
OriginalCall->addOperand(MachineOperand::CreateReg(
797-
MOP.getReg(), /*Def=*/false, /*Implicit=*/true));
797+
MOP.getReg(), /*Def=*/false, /*Implicit=*/true, /*isKill=*/false,
798+
/*isDead=*/false, /*isUndef=*/MOP.isUndef()));
798799
RegMaskStartIdx++;
799800
}
800801
for (const MachineOperand &MO :

llvm/test/CodeGen/AArch64/expand-blr-rvmarker-pseudo.mir

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: llc -run-pass=aarch64-expand-pseudo -mtriple=arm64-apple-ios -o - -emit-call-site-info %s | FileCheck %s
1+
# RUN: llc -run-pass=aarch64-expand-pseudo -mtriple=arm64-apple-ios -o - -emit-call-site-info %s -verify-machineinstrs | FileCheck %s
22

33
--- |
44
define void @test_1_callsite_info() {
@@ -25,7 +25,13 @@
2525
ret void
2626
}
2727

28+
define void @test_blr_undef_arg_in_x0() {
29+
ret void
30+
}
31+
2832
declare i8* @attachedcall()
33+
34+
declare ptr @objc_retainAutoreleasedReturnValue()
2935
...
3036
---
3137

@@ -132,3 +138,26 @@ body: |
132138
BLR_RVMARKER @attachedcall, $x8, $w0, $w1, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
133139
RET_ReallyLR implicit killed $w0
134140
...
141+
142+
# Test for https://github.com/llvm/llvm-project/issues/68005.
143+
#
144+
# CHECK-LABEL: : test_blr_undef_arg_in_x0
145+
# CHECK: bb.0:
146+
# CHECK-NEXT: liveins:
147+
# CHECK-NEXT: {{ $}}
148+
# 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 undef $x0, implicit $xzr, implicit $fp {
149+
# CHECK-NEXT: BL @foo, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit undef $x0, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
150+
# CHECK-NEXT: $fp = ORRXrs $xzr, $fp, 0
151+
# CHECK-NEXT: BL @objc_retainAutoreleasedReturnValue, implicit-def $lr, implicit internal $sp
152+
# CHECK-NEXT: }
153+
# CHECK-NEXT: RET undef $lr
154+
#
155+
name: test_blr_undef_arg_in_x0
156+
tracksRegLiveness: true
157+
body: |
158+
bb.0:
159+
liveins: $lr
160+
161+
BLR_RVMARKER @objc_retainAutoreleasedReturnValue, @foo, undef $x0, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $x0
162+
RET_ReallyLR
163+
...

0 commit comments

Comments
 (0)