From 1d28a759d95922068395de3a0a3d4353a63e2e07 Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Tue, 13 Mar 2018 06:47:04 +0000 Subject: [PATCH] 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 Signed-off-by: Yonghong Song llvm-svn: 327368 --- llvm/lib/Target/BPF/BPFMIPeephole.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/BPF/BPFMIPeephole.cpp b/llvm/lib/Target/BPF/BPFMIPeephole.cpp index b15a7e6..cf26f24 100644 --- a/llvm/lib/Target/BPF/BPFMIPeephole.cpp +++ b/llvm/lib/Target/BPF/BPFMIPeephole.cpp @@ -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); -- 2.7.4