As we want to avoid liveness update all the time, we maintain the liveness information dynamically during the phi mov optimization. Instruction(self-copy) remving bring unecessary complexity here. Let's avoid do that here, and do the self-copy removing latter in removeMOVs().
Signed-off-by: Zhigang Gong <zhigang.g...@intel.com> --- backend/src/ir/value.cpp | 6 +++--- backend/src/llvm/llvm_gen_backend.cpp | 21 +++++++-------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/backend/src/ir/value.cpp b/backend/src/ir/value.cpp index d2f0c2e..b0ed9c2 100644 --- a/backend/src/ir/value.cpp +++ b/backend/src/ir/value.cpp @@ -190,7 +190,7 @@ namespace ir { // Do not transfer dead values if (info.inLiveOut(reg) == false) continue; // If we overwrite it, do not transfer the initial value - if (info.inVarKill(reg) == true) continue; + if ((info.inVarKill(reg) == true) && (info.inUpwardUsed(reg))) continue; ValueDef *def = const_cast<ValueDef*>(this->dag.getDefAddress(&arg)); auto it = blockDefMap->find(reg); GBE_ASSERT(it != blockDefMap->end()); @@ -205,7 +205,7 @@ namespace ir { // Do not transfer dead values if (info.inLiveOut(reg) == false) continue; // If we overwrite it, do not transfer the initial value - if (info.inVarKill(reg) == true) continue; + if ((info.inVarKill(reg) == true) && (info.inUpwardUsed(reg))) continue; ValueDef *def = const_cast<ValueDef*>(this->dag.getDefAddress(reg)); auto it = blockDefMap->find(reg); GBE_ASSERT(it != blockDefMap->end()); @@ -219,7 +219,7 @@ namespace ir { // Do not transfer dead values if (info.inLiveOut(reg) == false) continue; // If we overwrite it, do not transfer the initial value - if (info.inVarKill(reg) == true) continue; + if ((info.inVarKill(reg) == true) && (info.inUpwardUsed(reg))) continue; ValueDef *def = const_cast<ValueDef*>(this->dag.getDefAddress(&pushed.second)); auto it = blockDefMap->find(reg); GBE_ASSERT(it != blockDefMap->end()); diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index b0b97e7..dc2e3e8 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -2149,6 +2149,11 @@ namespace gbe // destinations) uint32_t insnID = 2; bb.foreach([&](ir::Instruction &insn) { + if (insn.getOpcode() == ir::OP_MOV && + insn.getDst(0) == insn.getSrc(0)) { + insn.remove(); + return; + } const uint32_t dstNum = insn.getDstNum(); const uint32_t srcNum = insn.getSrcNum(); for (uint32_t srcID = 0; srcID < srcNum; ++srcID) { @@ -2245,8 +2250,7 @@ namespace gbe ++iter; } if (!phiPhiCopySrcInterfere) { - // phiCopy source can be coaleased with phiCopy - const_cast<Instruction *>(phiCopyDefInsn)->remove(); + replaceSrc(const_cast<Instruction *>(phiCopyDefInsn), phiCopySrc, phiCopy); for (auto &s : *phiCopySrcDef) { const Instruction *phiSrcDefInsn = s->getInstruction(); @@ -2300,7 +2304,7 @@ namespace gbe // coalease phi and phiCopy if (isOpt) { for (auto &x : *phiDef) { - const_cast<Instruction *>(x->getInstruction())->remove(); + replaceDst(const_cast<Instruction *>(x->getInstruction()), phi, phiCopy); } for (auto &x : *phiUse) { const Instruction *phiUseInsn = x->getInstruction(); @@ -2361,21 +2365,11 @@ namespace gbe const ir::UseSet *phiCopySrcUse = dag->getRegUse(phiCopySrc); for (auto &s : *phiCopySrcDef) { const Instruction *phiSrcDefInsn = s->getInstruction(); - if (phiSrcDefInsn->getOpcode() == ir::OP_MOV && - phiSrcDefInsn->getSrc(0) == phiCopy) { - const_cast<Instruction *>(phiSrcDefInsn)->remove(); - continue; - } replaceDst(const_cast<Instruction *>(phiSrcDefInsn), phiCopySrc, phiCopy); } for (auto &s : *phiCopySrcUse) { const Instruction *phiSrcUseInsn = s->getInstruction(); - if (phiSrcUseInsn->getOpcode() == ir::OP_MOV && - phiSrcUseInsn->getDst(0) == phiCopy) { - const_cast<Instruction *>(phiSrcUseInsn)->remove(); - continue; - } replaceSrc(const_cast<Instruction *>(phiSrcUseInsn), phiCopySrc, phiCopy); } @@ -2405,7 +2399,6 @@ namespace gbe } else break; - break; nextRedundant->clear(); replacedRegs.clear(); revReplacedRegs.clear(); -- 1.9.1 _______________________________________________ Beignet mailing list Beignet@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/beignet