Skip to content

Commit cf73a0b

Browse files
authored
[AArch64] Copy implicit def operands when creating LDP. (#164253)
Otherwise we might end up with undefined register uses. Copying implicit uses can cause problems where a register is both defined and used in the same LDP, so I have not tried to add them here. Fixes #164230
1 parent b21949e commit cf73a0b

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,25 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
13861386
if (MOP.isReg() && MOP.isKill())
13871387
DefinedInBB.addReg(MOP.getReg());
13881388

1389+
// Copy over any implicit-def operands. This is like MI.copyImplicitOps, but
1390+
// only copies implicit defs and makes sure that each operand is only added
1391+
// once in case of duplicates.
1392+
auto CopyImplicitOps = [&](MachineBasicBlock::iterator MI1,
1393+
MachineBasicBlock::iterator MI2) {
1394+
SmallSetVector<Register, 4> Ops;
1395+
for (const MachineOperand &MO :
1396+
llvm::drop_begin(MI1->operands(), MI1->getDesc().getNumOperands()))
1397+
if (MO.isReg() && MO.isImplicit() && MO.isDef())
1398+
Ops.insert(MO.getReg());
1399+
for (const MachineOperand &MO :
1400+
llvm::drop_begin(MI2->operands(), MI2->getDesc().getNumOperands()))
1401+
if (MO.isReg() && MO.isImplicit() && MO.isDef())
1402+
Ops.insert(MO.getReg());
1403+
for (auto Op : Ops)
1404+
MIB.addDef(Op, RegState::Implicit);
1405+
};
1406+
CopyImplicitOps(I, Paired);
1407+
13891408
// Erase the old instructions.
13901409
I->eraseFromParent();
13911410
Paired->eraseFromParent();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 6
2+
# RUN: llc -mtriple=aarch64-- -run-pass=aarch64-ldst-opt -verify-machineinstrs -o - %s | FileCheck %s
3+
# Check that we copy implicit operands.
4+
---
5+
name: impdef_op1
6+
tracksRegLiveness: true
7+
body: |
8+
bb.0:
9+
liveins: $lr
10+
; CHECK-LABEL: name: impdef_op1
11+
; CHECK: liveins: $lr
12+
; CHECK-NEXT: {{ $}}
13+
; CHECK-NEXT: renamable $q5, renamable $q20 = LDPQi renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
14+
; CHECK-NEXT: $q0 = ORRv16i8 $q4, killed $q4
15+
; CHECK-NEXT: $q1 = ORRv16i8 $q5, killed $q5
16+
; CHECK-NEXT: RET_ReallyLR
17+
renamable $q5 = LDRQui renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
18+
renamable $q20 = LDRQui renamable $lr, 4 :: (load (s128))
19+
$q0 = ORRv16i8 $q4, killed $q4
20+
$q1 = ORRv16i8 $q5, killed $q5
21+
RET_ReallyLR
22+
...
23+
---
24+
name: impdef_op2
25+
body: |
26+
bb.0:
27+
liveins: $lr
28+
; CHECK-LABEL: name: impdef_op2
29+
; CHECK: liveins: $lr
30+
; CHECK-NEXT: {{ $}}
31+
; CHECK-NEXT: renamable $q20, renamable $q5 = LDPQi renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
32+
; CHECK-NEXT: $q0 = ORRv16i8 $q4, killed $q4
33+
; CHECK-NEXT: $q1 = ORRv16i8 $q5, killed $q5
34+
; CHECK-NEXT: RET_ReallyLR
35+
renamable $q20 = LDRQui renamable $lr, 3 :: (load (s128))
36+
renamable $q5 = LDRQui renamable $lr, 4, implicit-def $q4_q5 :: (load (s128))
37+
$q0 = ORRv16i8 $q4, killed $q4
38+
$q1 = ORRv16i8 $q5, killed $q5
39+
RET_ReallyLR
40+
...
41+
---
42+
name: impdef_both
43+
body: |
44+
bb.0:
45+
liveins: $lr
46+
; CHECK-LABEL: name: impdef_both
47+
; CHECK: liveins: $lr
48+
; CHECK-NEXT: {{ $}}
49+
; CHECK-NEXT: renamable $q5, renamable $q20 = LDPQi renamable $lr, 3, implicit-def $q4_q5, implicit-def $q20_q21 :: (load (s128))
50+
; CHECK-NEXT: $q0 = ORRv16i8 $q4, killed $q4
51+
; CHECK-NEXT: $q1 = ORRv16i8 $q5, killed $q5
52+
; CHECK-NEXT: $q2 = ORRv16i8 $q20, killed $q20
53+
; CHECK-NEXT: $q3 = ORRv16i8 $q21, killed $q21
54+
; CHECK-NEXT: RET_ReallyLR
55+
renamable $q5 = LDRQui renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
56+
renamable $q20 = LDRQui renamable $lr, 4, implicit-def $q20_q21 :: (load (s128))
57+
$q0 = ORRv16i8 $q4, killed $q4
58+
$q1 = ORRv16i8 $q5, killed $q5
59+
$q2 = ORRv16i8 $q20, killed $q20
60+
$q3 = ORRv16i8 $q21, killed $q21
61+
RET_ReallyLR
62+
...
63+
---
64+
name: impdef_both_same
65+
body: |
66+
bb.0:
67+
liveins: $lr
68+
; CHECK-LABEL: name: impdef_both_same
69+
; CHECK: liveins: $lr
70+
; CHECK-NEXT: {{ $}}
71+
; CHECK-NEXT: renamable $q5, renamable $q20 = LDPQi renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
72+
; CHECK-NEXT: $q0 = ORRv16i8 $q4, killed $q4
73+
; CHECK-NEXT: $q1 = ORRv16i8 $q5, killed $q5
74+
; CHECK-NEXT: RET_ReallyLR
75+
renamable $q5 = LDRQui renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
76+
renamable $q20 = LDRQui renamable $lr, 4, implicit-def $q4_q5 :: (load (s128))
77+
$q0 = ORRv16i8 $q4, killed $q4
78+
$q1 = ORRv16i8 $q5, killed $q5
79+
RET_ReallyLR
80+
...

0 commit comments

Comments
 (0)