Skip to content

Commit 99d4859

Browse files
[llvm][AArch64] Preserve regmask when expanding the BLR_BTI pseudo instruction (#73927)
Fixes #73787 Not doing so lead to us making use of a register after the call, which has been clobbered by the call. Added an MIR test that runs only the pseudo expansion pass.
1 parent 402591a commit 99d4859

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ bool AArch64ExpandPseudo::expandCALL_BTI(MachineBasicBlock &MBB,
837837
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr();
838838
Call->addOperand(CallTarget);
839839
Call->setCFIType(*MBB.getParent(), MI.getCFIType());
840+
Call->copyImplicitOps(*MBB.getParent(), MI);
840841

841842
MachineInstr *BTI =
842843
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::HINT))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass=aarch64-expand-pseudo -o - %s | FileCheck %s
2+
3+
# When expanding a BLR_BTI, we should keep the regmask that was attached to it.
4+
# Otherwise we could end up using a register after the BL which was clobbered by
5+
# the function that was called.
6+
# CHECK: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit $sp {
7+
# CHECK: BL @_setjmp, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit-def dead $lr, implicit $sp, implicit-def $sp
8+
# CHECK: HINT 36
9+
# CHECK: }
10+
11+
--- |
12+
define void @a() {
13+
ret void
14+
}
15+
16+
declare void @_setjmp(...)
17+
...
18+
---
19+
name: a
20+
body: |
21+
bb.0:
22+
BLR_BTI @_setjmp, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp
23+
...

llvm/test/CodeGen/AArch64/kcfi-bti.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ define void @f2(ptr noundef %x) !kcfi_type !2 {
4949

5050
; KCFI: BUNDLE{{.*}} {
5151
; KCFI-NEXT: KCFI_CHECK $x0, 12345678, implicit-def $x9, implicit-def $x16, implicit-def $x17, implicit-def $nzcv
52-
; KCFI-NEXT: BLR killed $x0, implicit-def $lr, implicit $sp
52+
; KCFI-NEXT: BLR killed $x0, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit-def dead $lr, implicit $sp, implicit-def $sp
5353
; KCFI-NEXT: HINT 36
5454
; KCFI-NEXT: }
5555

0 commit comments

Comments
 (0)