Skip to content

Fix codegen-issues with multi-edge phi #27609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6242,7 +6242,10 @@ static std::unique_ptr<Module> emit_function(
workstack.push_back(lname - 1);
BasicBlock *ifnot = BB[lname];
BasicBlock *ifso = BB[cursor+2];
ctx.builder.CreateCondBr(isfalse, ifnot, ifso);
if (ifnot == ifso)
ctx.builder.CreateBr(ifnot);
else
ctx.builder.CreateCondBr(isfalse, ifnot, ifso);
find_next_stmt(cursor + 1);
continue;
}
Expand Down Expand Up @@ -6332,6 +6335,19 @@ static std::unique_ptr<Module> emit_function(
// This edge was statically unreachable. Don't codegen it.
if (!FromBB)
continue;
// We folded this branch to an unconditional branch, only codegen it once
if (cast<BranchInst>(FromBB->getTerminator())->isUnconditional()) {
bool found = false;
for (size_t j = 0; j < i; ++j) {
size_t j_edge = jl_unbox_long(jl_array_ptr_ref(edges, j));
if (j_edge == edge) {
found = true;
assert(jl_egal(value, jl_array_ptr_ref(values, j)));
}
}
if (found)
continue;
}
#ifndef JL_NDEBUG
if (FromBB) {
bool found_pred = false;
Expand Down
33 changes: 33 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6202,3 +6202,36 @@ function test27566(a,b)
end
test27566(a, b, c, d) = a.*(b, c, d)
@test test27566(1,1) == (1,0,1)

# Issue #27594
struct Iter27594 end
Base.iterate(::Iter27594) = (1, nothing)
Base.iterate(::Iter27594, ::Any) = nothing

function foo27594()
ind = 0
for x in (1,)
for y in Iter27594()
ind += 1
end
end
ind
end

@test foo27594() == 1

# Issue 27597
function f27597(y)
x = Int[]

if isempty(y)
y = 1:length(x)
elseif false
;
end

length(y)
return y
end
@test f27597([1]) == [1]
@test f27597([]) == 1:0