bpf: Support subregister definition check on PHI node

This patch relax the subregister definition check on Phi node.
Previously, we just cancel the optimizatoin when the definition is Phi
node while actually we could further check the definitions of incoming
parameters of PHI node.

This helps catch more elimination opportunities.

Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 327368
This commit is contained in:
Yonghong Song 2018-03-13 06:47:04 +00:00
parent c88bcdec43
commit 1d28a759d9
1 changed files with 16 additions and 2 deletions

View File

@ -76,9 +76,23 @@ bool BPFMIPeephole::isMovFrom32Def(MachineInstr *MovMI)
{
MachineInstr *DefInsn = MRI->getVRegDef(MovMI->getOperand(1).getReg());
if (!DefInsn || DefInsn->isPHI())
if (!DefInsn)
return false;
if (DefInsn->isPHI()) {
for (unsigned i = 1, e = DefInsn->getNumOperands(); i < e; i += 2) {
MachineOperand &opnd = DefInsn->getOperand(i);
if (!opnd.isReg())
return false;
MachineInstr *PhiDef = MRI->getVRegDef(opnd.getReg());
// quick check on PHI incoming definitions.
if (!PhiDef || PhiDef->isPHI() || PhiDef->getOpcode() == BPF::COPY)
return false;
}
}
if (DefInsn->getOpcode() == BPF::COPY) {
MachineOperand &opnd = DefInsn->getOperand(1);
@ -129,10 +143,10 @@ bool BPFMIPeephole::eliminateZExtSeq(void) {
MovMI->getOpcode() != BPF::MOV_32_64)
continue;
unsigned SubReg = MovMI->getOperand(1).getReg();
if (!isMovFrom32Def(MovMI))
continue;
unsigned SubReg = MovMI->getOperand(1).getReg();
BuildMI(MBB, MI, MI.getDebugLoc(), TII->get(BPF::SUBREG_TO_REG), DstReg)
.addImm(0).addReg(SubReg).addImm(BPF::sub_32);