Skip to content

Commit 9bbf0ec

Browse files
committed
[PowerPC] Fix the implicit operands in PredicateInstruction()
Summary: In the function `PPCInstrInfo::PredicateInstruction()`, we will replace non-Predicate Instructions to Predicate Instruction. But we forget add the new implicit operands the new Predicate Instruction needed. This patch is to fix this. Reviewed By: jsji, efriedma Differential Revision: https://reviews.llvm.org/D82390
1 parent a1b12a9 commit 9bbf0ec

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,10 @@ bool PPCInstrInfo::PredicateInstruction(MachineInstr &MI,
16751675
bool isPPC64 = Subtarget.isPPC64();
16761676
MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZLR8 : PPC::BDNZLR)
16771677
: (isPPC64 ? PPC::BDZLR8 : PPC::BDZLR)));
1678+
// Need add Def and Use for CTR implicit operand.
1679+
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1680+
.addReg(Pred[1].getReg(), RegState::Implicit)
1681+
.addReg(Pred[1].getReg(), RegState::ImplicitDefine);
16781682
} else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
16791683
MI.setDesc(get(PPC::BCLR));
16801684
MachineInstrBuilder(*MI.getParent()->getParent(), MI).add(Pred[1]);
@@ -1694,6 +1698,10 @@ bool PPCInstrInfo::PredicateInstruction(MachineInstr &MI,
16941698
bool isPPC64 = Subtarget.isPPC64();
16951699
MI.setDesc(get(Pred[0].getImm() ? (isPPC64 ? PPC::BDNZ8 : PPC::BDNZ)
16961700
: (isPPC64 ? PPC::BDZ8 : PPC::BDZ)));
1701+
// Need add Def and Use for CTR implicit operand.
1702+
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1703+
.addReg(Pred[1].getReg(), RegState::Implicit)
1704+
.addReg(Pred[1].getReg(), RegState::ImplicitDefine);
16971705
} else if (Pred[0].getImm() == PPC::PRED_BIT_SET) {
16981706
MachineBasicBlock *MBB = MI.getOperand(0).getMBB();
16991707
MI.RemoveOperand(0);
@@ -1734,19 +1742,24 @@ bool PPCInstrInfo::PredicateInstruction(MachineInstr &MI,
17341742
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8 : PPC::BCCTR8)
17351743
: (setLR ? PPC::BCCTRL : PPC::BCCTR)));
17361744
MachineInstrBuilder(*MI.getParent()->getParent(), MI).add(Pred[1]);
1737-
return true;
17381745
} else if (Pred[0].getImm() == PPC::PRED_BIT_UNSET) {
17391746
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCTRL8n : PPC::BCCTR8n)
17401747
: (setLR ? PPC::BCCTRLn : PPC::BCCTRn)));
17411748
MachineInstrBuilder(*MI.getParent()->getParent(), MI).add(Pred[1]);
1742-
return true;
1749+
} else {
1750+
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
1751+
: (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
1752+
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1753+
.addImm(Pred[0].getImm())
1754+
.add(Pred[1]);
17431755
}
17441756

1745-
MI.setDesc(get(isPPC64 ? (setLR ? PPC::BCCCTRL8 : PPC::BCCCTR8)
1746-
: (setLR ? PPC::BCCCTRL : PPC::BCCCTR)));
1747-
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1748-
.addImm(Pred[0].getImm())
1749-
.add(Pred[1]);
1757+
// Need add Def and Use for LR implicit operand.
1758+
if (setLR)
1759+
MachineInstrBuilder(*MI.getParent()->getParent(), MI)
1760+
.addReg(isPPC64 ? PPC::LR8 : PPC::LR, RegState::Implicit)
1761+
.addReg(isPPC64 ? PPC::LR8 : PPC::LR, RegState::ImplicitDefine);
1762+
17501763
return true;
17511764
}
17521765

llvm/test/CodeGen/PowerPC/ifcvt.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ body: |
4949
5050
5151
; CHECK-LABEL: name: testBDZLR
52-
; CHECK: BDZLR implicit $lr, implicit $rm
52+
; CHECK: BDZLR implicit $lr, implicit $rm, implicit $ctr, implicit-def $ctr
5353
...

0 commit comments

Comments
 (0)