Skip to content

Commit c1e2f39

Browse files
author
Krzysztof Parzyszek
committed
[PostRASink] Make sure to remove subregisters from live-ins as well
llvm-svn: 342492
1 parent 0594162 commit c1e2f39

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

llvm/lib/CodeGen/MachineSink.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,8 +1037,11 @@ static void clearKillFlags(MachineInstr *MI, MachineBasicBlock &CurBB,
10371037
static void updateLiveIn(MachineInstr *MI, MachineBasicBlock *SuccBB,
10381038
SmallVectorImpl<unsigned> &UsedOpsInCopy,
10391039
SmallVectorImpl<unsigned> &DefedRegsInCopy) {
1040-
for (auto DefReg : DefedRegsInCopy)
1041-
SuccBB->removeLiveIn(DefReg);
1040+
MachineFunction &MF = *SuccBB->getParent();
1041+
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
1042+
for (unsigned DefReg : DefedRegsInCopy)
1043+
for (MCSubRegIterator S(DefReg, TRI, true); S.isValid(); ++S)
1044+
SuccBB->removeLiveIn(*S);
10421045
for (auto U : UsedOpsInCopy) {
10431046
unsigned Reg = MI->getOperand(U).getReg();
10441047
if (!SuccBB->isLiveIn(Reg))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# RUN: llc -march=hexagon -run-pass postra-machine-sink,postrapseudos,if-converter -verify-machineinstrs -o - %s | FileCheck %s
2+
3+
# 1. Post-RA machine sinking moves the copy (1) to block %bb.1. The
4+
# subregisters $r2 and $r3 of $d1 are not removed from the live-ins.
5+
# 2. Expand post-RA pseudos replaces the COPY with A2_tfrp which is
6+
# predicable.
7+
# 3. If-conversion predicates block %bb.1. Since $d1 (made of $r2 and $r3)
8+
# is in the live-in list to %bb.1, it assumes that $d1 in (1) is live,
9+
# and adds an implicit use of $d1 to the predicated copy.
10+
# This results in an invalid machine code, since the implicit use
11+
# refers to an undefined register.
12+
13+
# Make sure that post-RA machine sinking removes subregisters from live-ins
14+
# to block bb.1.
15+
16+
# CHECK: $d1 = A2_tfrpf $p0, $d0
17+
# CHECK-NOT: implicit killed $d1
18+
19+
name: fred
20+
tracksRegLiveness: true
21+
body: |
22+
bb.0:
23+
liveins: $d0, $p0
24+
renamable $d1 = COPY $d0 ;; (1)
25+
J2_jumpt $p0, %bb.2, implicit-def $pc
26+
bb.1:
27+
liveins: $r2, $r3
28+
$r0 = A2_addi $r2, 1
29+
bb.2:
30+
liveins: $r0
31+
A2_nop
32+
J2_jumpr $r31, implicit-def $pc
33+
...

0 commit comments

Comments
 (0)