How to read φ and π in @code_typed output?

Take for example the following snippet.

5 ──       goto #6
6 ── %26 = Base.sub_float(%23, 1.0)::Float64
└───       goto #7
7 ──       goto #8
8 ──       goto #9
9 ── %30 = Base.lt_float(0.5, %26)::Bool
└───       goto #11 if not %30
10 ─       goto #12
11 ─       nothing::Nothing
12 ┄ %34 = φ (#10 => 2, #11 => _2)::Union{Float64, Int64}
│    %35 = (isa)(%34, Float64)::Bool
└───       goto #14 if not %35
13 ─ %37 = π (%34, Float64)
│    %38 = Base.div_float(4.0, %37)::Float64
└───       goto #17
14 ─ %40 = (isa)(%34, Int64)::Bool
└───       goto #16 if not %40
15 ─ %42 = π (%34, Int64)
│    %43 = Base.mul_int(3, %42)::Int64
└───       goto #17
16 ─       Core.throw(ErrorException("fatal error in type inference (type bound)"))::Union{}
└───       $(Expr(:unreachable))::Union{}
17 ┄ %47 = φ (#13 => %38, #15 => %43)::Union{Float64, Int64}
└───       return %47

How to read the first lines of branches 12, 13, 15, and 17?

2 Likes

This is a good explanation of phi nodes: Comp.compilers: Re: Phi nodes?

4 Likes

Thank you! That explains the φ nodes. Using this information I found more info on the π nodes here: Julia SSA-form IR · The Julia Language

1 Like