diff --git a/Compiler/src/optimize.jl b/Compiler/src/optimize.jl index 3532b2043d76f..458d30f4bcbe5 100644 --- a/Compiler/src/optimize.jl +++ b/Compiler/src/optimize.jl @@ -1245,8 +1245,7 @@ function convert_to_ircode(ci::CodeInfo, sv::OptimizationState) empty!(sv.cfg.blocks[block].succs) if !(idx < length(code) && isa(code[idx + 1], ReturnNode) && !isdefined((code[idx + 1]::ReturnNode), :val)) - # Any statements from here to the end of the block have been wrapped in Core.Const(...) - # by type inference (effectively deleting them). Only task left is to replace the block + # Any statements from here to the end of the block are unreachable. Replace the block # terminator with an explicit `unreachable` marker. if block_end > idx diff --git a/Compiler/src/ssair/slot2ssa.jl b/Compiler/src/ssair/slot2ssa.jl index d9ea2539f0ffc..68961b671cc6e 100644 --- a/Compiler/src/ssair/slot2ssa.jl +++ b/Compiler/src/ssair/slot2ssa.jl @@ -638,10 +638,10 @@ function construct_ssa!(ci::CodeInfo, ir::IRCode, sv::OptimizationState, end phiblocks = iterated_dominance_frontier(cfg, live, domtree) for block in phiblocks + varstate = sv.bb_vartables[block] + varstate === nothing && continue push!(phi_slots[block], idx) node = PhiNode() - varstate = sv.bb_vartables[block] - @assert varstate !== nothing vt = varstate[idx] ssaval = NewSSAValue(insert_node!(ir, first_insert_for_bb(code, cfg, block), NewInstruction(node, vt.typ)).id - length(ir.stmts)) diff --git a/Compiler/src/typeinfer.jl b/Compiler/src/typeinfer.jl index dacde593fe1f2..96ce96ce49a26 100644 --- a/Compiler/src/typeinfer.jl +++ b/Compiler/src/typeinfer.jl @@ -870,9 +870,8 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState) if is_meta_expr(expr) # keep any lexically scoped expressions ssavaluetypes[i] = Any # 3 else - ssavaluetypes[i] = Bottom # 3 # annotate that this statement actually is dead - stmts[i] = Const(expr) + ssavaluetypes[i] = Bottom # 3 end end end diff --git a/Compiler/test/ssair.jl b/Compiler/test/ssair.jl index a855439877f1b..44ef74b4b93a5 100644 --- a/Compiler/test/ssair.jl +++ b/Compiler/test/ssair.jl @@ -721,18 +721,18 @@ end return x end let - # At least some statements should have been found to be statically unreachable and wrapped in Const(...)::Union{} + # At least some statements should have been found to be statically unreachable unopt = code_typed1(f_with_maybe_nonbool_cond, (Int, Bool); optimize=false) - @test any(j -> isa(unopt.code[j], Core.Const) && unopt.ssavaluetypes[j] == Union{}, 1:length(unopt.code)) + @test any(j -> unopt.ssavaluetypes[j] === Union{}, 1:length(unopt.code)) # Any GotoIfNot destinations after IRCode conversion should not be statically unreachable ircode = first(only(Base.code_ircode(f_with_maybe_nonbool_cond, (Int, Bool); optimize_until="CC: CONVERT"))) for i = 1:length(ircode.stmts) expr = ircode.stmts[i][:stmt] if isa(expr, GotoIfNot) - # If this statement is Core.Const(...)::Union{}, that means this code was not reached - @test !(isa(ircode.stmts[i+1][:stmt], Core.Const) && (unopt.ssavaluetypes[i+1] === Union{})) - @test !(isa(ircode.stmts[expr.dest][:stmt], Core.Const) && (unopt.ssavaluetypes[expr.dest] === Union{})) + # GotoIfNot branch destinations should not be unreachable + @test !(unopt.ssavaluetypes[i+1] === Union{}) + @test !(unopt.ssavaluetypes[expr.dest] === Union{}) end end end