From fe24e0316f77d987d8353745e95a8a6160e82855 Mon Sep 17 00:00:00 2001 From: Greg Fischer Date: Tue, 11 Jul 2017 16:52:19 -0600 Subject: [PATCH] LocalMultiStore: Always put varId for backedge on loop phi function. And always patch the backedge operand when patching phi functions. This approach is more correct and cleaner. The previous code was generating incorrect phis when the backedge block had no predecessors. --- source/opt/local_ssa_elim_pass.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/opt/local_ssa_elim_pass.cpp b/source/opt/local_ssa_elim_pass.cpp index 8ddb6e6..890f893 100644 --- a/source/opt/local_ssa_elim_pass.cpp +++ b/source/opt/local_ssa_elim_pass.cpp @@ -460,7 +460,7 @@ void LocalMultiStoreElimPass::SSABlockInitLoopHeader( continue; } // Val differs across predecessors. Add phi op to block and - // add its result id to the map. For live back edge predecessor, + // add its result id to the map. For back edge predecessor, // use the variable id. We will patch this after visiting back // edge predecessor. For predecessors that do not define a value, // use undef. @@ -469,10 +469,7 @@ void LocalMultiStoreElimPass::SSABlockInitLoopHeader( for (uint32_t predLabel : label2preds_[label]) { uint32_t valId; if (predLabel == backLabel) { - if (val0Id == 0) - valId = varId; - else - valId = Type2Undef(typeId); + valId = varId; } else { const auto var_val_itr = label2ssa_map_[predLabel].find(varId); @@ -594,14 +591,15 @@ void LocalMultiStoreElimPass::PatchPhis(uint32_t header_id, uint32_t back_id) { if (cnt % 2 == 1 && *iid == back_id) idx = cnt - 1; ++cnt; }); - // Only patch operands that are in the backedge predecessor map + // Use undef if variable not in backedge predecessor map const uint32_t varId = phiItr->GetSingleWordInOperand(idx); const auto valItr = label2ssa_map_[back_id].find(varId); - if (valItr != label2ssa_map_[back_id].end()) { - phiItr->SetInOperand(idx, { valItr->second }); - // Analyze uses now that they are complete - def_use_mgr_->AnalyzeInstUse(&*phiItr); - } + uint32_t valId = (valItr != label2ssa_map_[back_id].end()) ? + valItr->second : + Type2Undef(GetPointeeTypeId(def_use_mgr_->GetDef(varId))); + phiItr->SetInOperand(idx, { valId }); + // Analyze uses now that they are complete + def_use_mgr_->AnalyzeInstUse(&*phiItr); } } -- 2.7.4