Skip to content

Commit

Permalink
Merge pull request #27228 from JuliaLang/kf/pinodearg
Browse files Browse the repository at this point in the history
Handle PiNodes of arguments in type lifting
  • Loading branch information
Keno committed May 27, 2018
2 parents 7144b6b + 6fff460 commit f6af5bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 4 additions & 12 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,10 @@ function type_lift_pass!(ir::IRCode)
# node (or an UpsilonNode() argument to a PhiC node),
# so lift all these nodes that have maybe undef values
processed = IdDict{Int, Union{SSAValue, Bool}}()
if !isa(val, SSAValue)
while isa(val, SSAValue) && isa(ir.stmts[val.id], PiNode)
val = ir.stmts[val.id].val
end
if !isa(val, SSAValue) || (!isa(ir.stmts[val.id], PhiNode) && !isa(ir.stmts[val.id], PhiCNode))
(isa(val, GlobalRef) || isexpr(val, :static_parameter)) && continue
if stmt.head === :undefcheck
ir.stmts[idx] = nothing
Expand All @@ -843,19 +846,8 @@ function type_lift_pass!(ir::IRCode)
continue
end
stmt_id = val.id
while isa(ir.stmts[stmt_id], PiNode)
stmt_id = ir.stmts[stmt_id].val.id
end
worklist = Tuple{Int, Int, SSAValue, Int}[(stmt_id, 0, SSAValue(0), 0)]
def = ir.stmts[stmt_id]
if !isa(def, PhiNode) && !isa(def, PhiCNode)
if stmt.head === :isdefined
ir.stmts[idx] = true
else
ir.stmts[idx] = nothing
end
continue
end
if !haskey(lifted_undef, stmt_id)
first = true
while !isempty(worklist)
Expand Down
11 changes: 11 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6127,3 +6127,14 @@ end
foo27204(x) = f27204(x)()
@test foo27204(true) == 1
@test foo27204(false) == 2

# Issue 27209
@noinline function f27209(x::Union{Float64, Nothing})
if x === nothing
y = x; return @isdefined(y)
else
return @isdefined(y)
end
end
g27209(x) = f27209(x ? nothing : 1.0)
@test g27209(true) == true

0 comments on commit f6af5bf

Please sign in to comment.