diff --git a/src/cleanup.jl b/src/cleanup.jl index 57487b7..6ba30c5 100644 --- a/src/cleanup.jl +++ b/src/cleanup.jl @@ -8,7 +8,11 @@ function inline_consts!(ir::IR) isused(x) = get(us, x, 0) > 0 for v in reverse(keys(ir)) st = ir[v] - effect = effectful(exprtype.((ir,), ir[v].expr.args)...) + if typeof(st.expr) == IRTools.Inner.Variable + effect = true + else + effect = effectful(exprtype.((ir,), ir[v].expr.args)...) + end if st.type isa Union{Const,Node} && !effect map(v -> v isa Variable && (us[v] -= 1), st.expr.args) if st.type isa Node || istrivial(st.type.value) || !isused(v) diff --git a/src/infer.jl b/src/infer.jl index 9edc3ba..c4b67e6 100644 --- a/src/infer.jl +++ b/src/infer.jl @@ -196,6 +196,18 @@ function step!(inf::Inference) end elseif isexpr(st.expr, :inbounds) push!(inf.queue, (frame, b, f, ip+1)) + elseif typeof(st.expr) == IRTools.Inner.Variable + if (i = findfirst(x -> x == st.expr, arguments(block))) != nothing + T = argtypes(block)[i] + elseif st.expr in stmts + T = block.ir[st.expr].type + else + error("Unrecognised variable $(st.expr)") + end + if T != Union{} + block.ir[var] = stmt(block[var], type = _union(st.type, T)) + push!(inf.queue, (frame, b, f, ip+1)) + end else error("Unrecognised expression $(st.expr)") end