Skip to content

Commit

Permalink
[NewOptimizer] Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno authored and StefanKarpinski committed May 10, 2018
1 parent 89e992b commit 8f3b986
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions base/compiler/ssair/inlining2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function minimal_backinf(compact, constraints, unconstrained_types, argexprs)
unconstrained_types
end

function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int,
function ir_inline_unionsplit!(compact::IncrementalCompact, topmod::Module, idx::Int,
argexprs::Vector{Any}, linetable::Vector{LineInfoNode},
item::UnionSplit, boundscheck::Symbol, todo_bbs::Vector{Tuple{Int, Int}})
stmt, typ, line = compact.result[idx], compact.result_types[idx], compact.result_lines[idx]
Expand Down Expand Up @@ -480,7 +480,7 @@ function ir_inline_unionsplit!(compact::IncrementalCompact, idx::Int,
bb += 1
# We're now in the fall through block, decide what to do
if item.fully_covered
e = Expr(:call, :error, "fatal error in type inference (type bound)")
e = Expr(:call, GlobalRef(topmod, :error), "fatal error in type inference (type bound)")
e.typ = Union{}
insert_node_here!(compact, e, Union{}, line)
insert_node_here!(compact, ReturnNode(), Union{}, line)
Expand Down Expand Up @@ -548,7 +548,7 @@ function batch_inline!(todo::Vector{Any}, ir::IRCode, linetable::Vector{LineInfo
if isa(item, InliningTodo)
compact.ssa_rename[compact.idx-1] = ir_inline_item!(compact, idx, argexprs, linetable, item, boundscheck, state.todo_bbs)
elseif isa(item, UnionSplit)
ir_inline_unionsplit!(compact, idx, argexprs, linetable, item, boundscheck, state.todo_bbs)
ir_inline_unionsplit!(compact, _topmod(sv.mod), idx, argexprs, linetable, item, boundscheck, state.todo_bbs)
end
compact[idx] = nothing
refinish && finish_current_bb!(compact)
Expand Down
17 changes: 11 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,11 @@ static jl_cgval_t convert_julia_type_union(jl_codectx_t &ctx, const jl_cgval_t &
Value *union_box_dt = NULL;
BasicBlock *union_isaBB = NULL;
auto maybe_setup_union_isa = [&]() {
union_isaBB = BasicBlock::Create(jl_LLVMContext, "union_isa", ctx.f);
ctx.builder.SetInsertPoint(union_isaBB);
union_box_dt = emit_typeof(ctx, v.Vboxed);
if (!union_isaBB) {
union_isaBB = BasicBlock::Create(jl_LLVMContext, "union_isa", ctx.f);
ctx.builder.SetInsertPoint(union_isaBB);
union_box_dt = emit_typeof(ctx, v.Vboxed);
}
};

// If we don't find a match. The type remains unknown
Expand Down Expand Up @@ -6583,7 +6585,9 @@ static std::unique_ptr<Module> emit_function(
if (val.constant)
val = mark_julia_const(val.constant); // be over-conservative at making sure `.typ` is set concretely, not tindex
TerminatorInst *terminator = FromBB->getTerminator();
if (!isa<BranchInst>(terminator) || cast<BranchInst>(terminator)->isConditional()) {
if (!isa<BranchInst>(terminator) ||
(cast<BranchInst>(terminator)->isConditional() &&
!(terminator->getSuccessor(0) == terminator->getSuccessor(1)))) {
bool found = false;
for (size_t i = 0; i < terminator->getNumSuccessors(); ++i) {
if (terminator->getSuccessor(i) == PhiBB) {
Expand All @@ -6595,14 +6599,15 @@ static std::unique_ptr<Module> emit_function(
Function::iterator FBBI = FromBB->getIterator();
ctx.f->getBasicBlockList().insert(++FBBI, NewBB);
ctx.builder.SetInsertPoint(NewBB);
terminator = BranchInst::Create(PhiBB);
found = true;
break;
}
}
assert(found);
}
else {
terminator->eraseFromParent();
terminator->removeFromParent();
ctx.builder.SetInsertPoint(FromBB);
}
if (!jl_is_uniontype(phiType) || !TindexN) {
Expand Down Expand Up @@ -6675,7 +6680,7 @@ static std::unique_ptr<Module> emit_function(
if (TindexN)
TindexN->addIncoming(RTindex, ctx.builder.GetInsertBlock());
}
ctx.builder.CreateBr(PhiBB);
ctx.builder.Insert(terminator);
// Check any phi nodes in the Phi block to see if by splitting the edges,
// we made things inconsistent
if (FromBB != ctx.builder.GetInsertBlock()) {
Expand Down

0 comments on commit 8f3b986

Please sign in to comment.