Skip to content

Commit 228aecb

Browse files
[llvm][AArch64] Copy all operands when expanding BLR_BTI bundle (#78267)
Fixes #77915 Previously I based the operand copying on expandCALL_RVMARKER but did not understand it properly at the time. This lead to me dropping the arguments of the function being branched to. This fixes that by copying all operands from the BLR_BTI to the BL/BLR without skipping anything. I've updated the existing test by adding function arguments.
1 parent 12b676d commit 228aecb

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,11 @@ bool AArch64ExpandPseudo::expandCALL_BTI(MachineBasicBlock &MBB,
842842
unsigned Opc = CallTarget.isGlobal() ? AArch64::BL : AArch64::BLR;
843843
MachineInstr *Call =
844844
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(Opc)).getInstr();
845-
Call->addOperand(CallTarget);
845+
846+
for (const MachineOperand &MO : MI.operands())
847+
Call->addOperand(MO);
848+
846849
Call->setCFIType(*MBB.getParent(), MI.getCFIType());
847-
Call->copyImplicitOps(*MBB.getParent(), MI);
848850

849851
MachineInstr *BTI =
850852
BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::HINT))
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 copy all the operands to the branch in the
4+
# bundle. Otherwise we could end up using a register after the BL which was
5+
# clobbered by the function that was called, or overwriting an argument to that
6+
# function before we make the call.
7+
# CHECK: BUNDLE implicit-def $lr, implicit-def $w30, implicit-def $sp, implicit-def $wsp, implicit $x0, implicit $w1, implicit $sp {
8+
# CHECK: BL @_setjmp, $x0, $w1, csr_aarch64_aapcs, implicit-def $lr, implicit $sp, implicit-def dead $lr, implicit $sp, implicit-def $sp
9+
# CHECK: HINT 36
10+
# CHECK: }
11+
12+
--- |
13+
define void @a() {
14+
ret void
15+
}
16+
17+
declare void @_setjmp(...)
18+
...
19+
---
20+
name: a
21+
body: |
22+
bb.0:
23+
BLR_BTI @_setjmp, $x0, $w1, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp
24+
...

llvm/test/CodeGen/AArch64/blr-bti-preserves-regmask.mir

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)