Skip to content

Commit 152f49d

Browse files
committed
Add an extra testcase with duplicate implicitdefs and make sure that implicit-defs are unique.
1 parent 9b4b4a4 commit 152f49d

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,15 +1387,23 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
13871387
DefinedInBB.addReg(MOP.getReg());
13881388

13891389
// Copy over any implicit-def operands. This is like MI.copyImplicitOps, but
1390-
// only copies implicit defs.
1391-
auto CopyImplicitOps = [&](MachineBasicBlock::iterator MI) {
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;
13921395
for (const MachineOperand &MO :
1393-
llvm::drop_begin(MI->operands(), MI->getDesc().getNumOperands()))
1396+
llvm::drop_begin(MI1->operands(), MI1->getDesc().getNumOperands()))
13941397
if (MO.isReg() && MO.isImplicit() && MO.isDef())
1395-
MIB.add(MO);
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);
13961405
};
1397-
CopyImplicitOps(I);
1398-
CopyImplicitOps(Paired);
1406+
CopyImplicitOps(I, Paired);
13991407

14001408
// Erase the old instructions.
14011409
I->eraseFromParent();

llvm/test/CodeGen/AArch64/ldst-implicitop.mir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,32 @@ body: |
4949
; CHECK-NEXT: renamable $q5, renamable $q20 = LDPQi renamable $lr, 3, implicit-def $q4_q5, implicit-def $q20_q21 :: (load (s128))
5050
; CHECK-NEXT: $q0 = ORRv16i8 $q4, killed $q4
5151
; CHECK-NEXT: $q1 = ORRv16i8 $q5, killed $q5
52+
; CHECK-NEXT: $q2 = ORRv16i8 $q20, killed $q20
53+
; CHECK-NEXT: $q3 = ORRv16i8 $q21, killed $q21
5254
; CHECK-NEXT: RET_ReallyLR
5355
renamable $q5 = LDRQui renamable $lr, 3, implicit-def $q4_q5 :: (load (s128))
5456
renamable $q20 = LDRQui renamable $lr, 4, implicit-def $q20_q21 :: (load (s128))
5557
$q0 = ORRv16i8 $q4, killed $q4
5658
$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
5779
RET_ReallyLR
5880
...

0 commit comments

Comments
 (0)