Skip to content

Commit 5a062fa

Browse files
authored
Merge pull request #26958 from JuliaLang/kf/placateverifier
[NewOptimizer] Placate LLVM IR verifier
2 parents 64040ce + b199a69 commit 5a062fa

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/codegen.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6547,6 +6547,7 @@ static std::unique_ptr<Module> emit_function(
65476547

65486548
// Codegen Phi nodes
65496549
std::map<BasicBlock *, BasicBlock*> BB_rewrite_map;
6550+
std::vector<llvm::PHINode*> ToDelete;
65506551
for (auto &tup : ctx.PhiNodes) {
65516552
jl_cgval_t phi_result;
65526553
PHINode *VN;
@@ -6724,6 +6725,16 @@ static std::unique_ptr<Module> emit_function(
67246725
}
67256726
}
67266727
}
6728+
// In LLVM IR it is illegal to have phi nodes without incoming values, even if
6729+
// there are no operands, so delete any such phi nodes
6730+
if (pred_begin(PhiBB) == pred_end(PhiBB))
6731+
{
6732+
if (VN)
6733+
ToDelete.push_back(VN);
6734+
if (TindexN)
6735+
ToDelete.push_back(TindexN);
6736+
continue;
6737+
}
67276738
// Julia PHINodes may be incomplete with respect to predecessors, LLVM's may not
67286739
Value *VNUndef = nullptr;
67296740
for (auto *pred : predecessors(PhiBB)) {
@@ -6748,6 +6759,11 @@ static std::unique_ptr<Module> emit_function(
67486759
}
67496760
}
67506761

6762+
for (PHINode *PN : ToDelete) {
6763+
PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
6764+
PN->eraseFromParent();
6765+
}
6766+
67516767
UndefAlloca->setOperand(0, ConstantInt::get(T_size, undef_alloca_bytes));
67526768
UndefAlloca->setAlignment(undef_alloca_align);
67536769

0 commit comments

Comments
 (0)