Skip to content

Commit

Permalink
Merge pull request #26958 from JuliaLang/kf/placateverifier
Browse files Browse the repository at this point in the history
[NewOptimizer] Placate LLVM IR verifier
  • Loading branch information
Keno authored May 2, 2018
2 parents 64040ce + b199a69 commit 5a062fa
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6547,6 +6547,7 @@ static std::unique_ptr<Module> emit_function(

// Codegen Phi nodes
std::map<BasicBlock *, BasicBlock*> BB_rewrite_map;
std::vector<llvm::PHINode*> ToDelete;
for (auto &tup : ctx.PhiNodes) {
jl_cgval_t phi_result;
PHINode *VN;
Expand Down Expand Up @@ -6724,6 +6725,16 @@ static std::unique_ptr<Module> emit_function(
}
}
}
// In LLVM IR it is illegal to have phi nodes without incoming values, even if
// there are no operands, so delete any such phi nodes
if (pred_begin(PhiBB) == pred_end(PhiBB))
{
if (VN)
ToDelete.push_back(VN);
if (TindexN)
ToDelete.push_back(TindexN);
continue;
}
// Julia PHINodes may be incomplete with respect to predecessors, LLVM's may not
Value *VNUndef = nullptr;
for (auto *pred : predecessors(PhiBB)) {
Expand All @@ -6748,6 +6759,11 @@ static std::unique_ptr<Module> emit_function(
}
}

for (PHINode *PN : ToDelete) {
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
PN->eraseFromParent();
}

UndefAlloca->setOperand(0, ConstantInt::get(T_size, undef_alloca_bytes));
UndefAlloca->setAlignment(undef_alloca_align);

Expand Down

0 comments on commit 5a062fa

Please sign in to comment.