Skip to content

Commit 4bb0a1c

Browse files
committed
[PowerPC] Fix the liveins for ppc-expand-isel pass
Summary: In the ppc-expand-isel pass, we use stepForward() to update the liveins, this function is not recommended, because it needs the accurate kill info. This patch uses the function computeAndAddLiveIns() to update the liveins, it's the recommended method and can fix the liveins bug for ppc-expand-isel pass.. Reviewed By: efriedma, lkail Differential Revision: https://reviews.llvm.org/D78657
1 parent be884b7 commit 4bb0a1c

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

llvm/lib/Target/PowerPC/PPCExpandISEL.cpp

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -381,21 +381,10 @@ void PPCExpandISEL::reorganizeBlockLayout(BlockISELList &BIL,
381381
MBB->end());
382382
NewSuccessor->transferSuccessorsAndUpdatePHIs(MBB);
383383

384-
// Copy the original liveIns of MBB to NewSuccessor.
385-
for (auto &LI : MBB->liveins())
386-
NewSuccessor->addLiveIn(LI);
387-
388-
// After splitting the NewSuccessor block, Regs defined but not killed
389-
// in MBB should be treated as liveins of NewSuccessor.
390-
// Note: Cannot use stepBackward instead since we are using the Reg
391-
// liveness state at the end of MBB (liveOut of MBB) as the liveIn for
392-
// NewSuccessor. Otherwise, will cause cyclic dependence.
393-
LivePhysRegs LPR(*MF->getSubtarget<PPCSubtarget>().getRegisterInfo());
394-
SmallVector<std::pair<MCPhysReg, const MachineOperand *>, 2> Clobbers;
395-
for (MachineInstr &MI : *MBB)
396-
LPR.stepForward(MI, Clobbers);
397-
for (auto &LI : LPR)
398-
NewSuccessor->addLiveIn(LI);
384+
// Update the liveins for NewSuccessor.
385+
LivePhysRegs LPR;
386+
computeAndAddLiveIns(LPR, *NewSuccessor);
387+
399388
} else {
400389
// Remove successor from MBB.
401390
MBB->removeSuccessor(Successor);
@@ -453,32 +442,15 @@ void PPCExpandISEL::populateBlocks(BlockISELList &BIL) {
453442
bool IsADDIInstRequired = !useSameRegister(Dest, TrueValue);
454443
bool IsORIInstRequired = !useSameRegister(Dest, FalseValue);
455444

456-
if (IsADDIInstRequired) {
457-
// Copy the result into the destination if the condition is true.
445+
// Copy the result into the destination if the condition is true.
446+
if (IsADDIInstRequired)
458447
BuildMI(*TrueBlock, TrueBlockI, dl,
459448
TII->get(isISEL8(*MI) ? PPC::ADDI8 : PPC::ADDI))
460449
.add(Dest)
461450
.add(TrueValue)
462451
.add(MachineOperand::CreateImm(0));
463452

464-
// Add the LiveIn registers required by true block.
465-
TrueBlock->addLiveIn(TrueValue.getReg());
466-
}
467-
468-
if (IsORIInstRequired) {
469-
// Add the LiveIn registers required by false block.
470-
FalseBlock->addLiveIn(FalseValue.getReg());
471-
}
472-
473-
if (NewSuccessor) {
474-
// Add the LiveIn registers required by NewSuccessor block.
475-
NewSuccessor->addLiveIn(Dest.getReg());
476-
NewSuccessor->addLiveIn(TrueValue.getReg());
477-
NewSuccessor->addLiveIn(FalseValue.getReg());
478-
NewSuccessor->addLiveIn(ConditionRegister.getReg());
479-
}
480-
481-
// Copy the value into the destination if the condition is false.
453+
// Copy the result into the destination if the condition is false.
482454
if (IsORIInstRequired)
483455
BuildMI(*FalseBlock, FalseBlockI, dl,
484456
TII->get(isISEL8(*MI) ? PPC::ORI8 : PPC::ORI))
@@ -490,6 +462,18 @@ void PPCExpandISEL::populateBlocks(BlockISELList &BIL) {
490462

491463
NumExpanded++;
492464
}
465+
466+
if (IsTrueBlockRequired) {
467+
// Update the liveins for TrueBlock.
468+
LivePhysRegs LPR;
469+
computeAndAddLiveIns(LPR, *TrueBlock);
470+
}
471+
472+
if (IsFalseBlockRequired) {
473+
// Update the liveins for FalseBlock.
474+
LivePhysRegs LPR;
475+
computeAndAddLiveIns(LPR, *FalseBlock);
476+
}
493477
}
494478

495479
void PPCExpandISEL::expandMergeableISELs(BlockISELList &BIL) {

llvm/test/CodeGen/PowerPC/expand-isel-liveness.mir

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ body: |
3838
3939
; CHECK-LABEL: name: expand_isel_liveness1
4040
; CHECK: bb.1:
41-
; CHECK: liveins: $x7
41+
; CHECK: liveins: $x3, $x4, $x7
4242
; CHECK: renamable $x5 = ORI8 killed renamable $x7, 0
4343
; CHECK: B %bb.3
4444
; CHECK: bb.2:
45-
; CHECK: liveins: $zero8
45+
; CHECK: liveins: $x3, $x4
4646
; CHECK: renamable $x5 = ADDI8 $zero8, 0
4747
; CHECK: bb.3:
48-
; CHECK: liveins: $x3, $x4, $x5, $x6, $cr1lt, $cr1gt, $x3, $cr6lt, $cr0eq, $r3, $cr5un, $cr1eq, $cr1un, $cr6un, $cr0lt, $cr0gt, $cr6gt, $cr0un, $cr1, $cr6, $cr5eq, $x8, $r8, $cr6eq, $x4, $r4, $cr0, $cr5gt, $cr5, $cr5lt, $x7, $r7, $x5, $r5, $x5, $zero8, $x7, $cr5lt
48+
; CHECK: liveins: $x3, $x4, $x5
4949
; CHECK: BLR8 implicit $lr8, implicit $rm, implicit killed $x3, implicit killed $x4, implicit killed $x5
5050
...
5151

@@ -74,7 +74,7 @@ body: |
7474
; CHECK: $r3 = ORI killed $r0, 0
7575
; CHECK: B %bb.3
7676
; CHECK: bb.2.entry:
77-
; CHECK: liveins: $zero
77+
; CHECK-NOT: liveins: $zero
7878
; CHECK: $r3 = ADDI $zero, 0
7979
...
8080

0 commit comments

Comments
 (0)