Skip to content

Commit 9b4b4a4

Browse files
committed
[AArch64] Copy implicit def operands when creating LDP.
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 6ad25c5 commit 9b4b4a4

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,17 @@ 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.
1391+
auto CopyImplicitOps = [&](MachineBasicBlock::iterator MI) {
1392+
for (const MachineOperand &MO :
1393+
llvm::drop_begin(MI->operands(), MI->getDesc().getNumOperands()))
1394+
if (MO.isReg() && MO.isImplicit() && MO.isDef())
1395+
MIB.add(MO);
1396+
};
1397+
CopyImplicitOps(I);
1398+
CopyImplicitOps(Paired);
1399+
13891400
// Erase the old instructions.
13901401
I->eraseFromParent();
13911402
Paired->eraseFromParent();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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: RET_ReallyLR
53+
renamable $q5 = LDRQui renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
54+
renamable $q20 = LDRQui renamable $lr, 4, implicit-def $q20_q21 :: (load (s128))
55+
$q0 = ORRv16i8 $q4, killed $q4
56+
$q1 = ORRv16i8 $q5, killed $q5
57+
RET_ReallyLR
58+
...

0 commit comments

Comments
 (0)