Skip to content

loops inhibit constant prop #41694

@simeonschaub

Description

@simeonschaub

Minimal example:

julia> function fact(x)
           res = 1
           while x > 1
               res *= x
               x -= 1
           end
           return res
       end
fact (generic function with 1 method)

julia> code_typed() do
           fact(1)
       end
1-element Vector{Any}:
 CodeInfo(
1return 1
) => Int64

julia> code_typed() do
           fact(2)
       end
1-element Vector{Any}:
 CodeInfo(
1nothing::Nothing
2%2 = φ (#1 => 1, #3 => %6)::Int64%3 = φ (#1 => 2, #3 => %7)::Int64%4 = Base.slt_int(1, %3)::Bool
└──      goto #4 if not %4
3%6 = Base.mul_int(%2, %3)::Int64%7 = Base.sub_int(%3, 1)::Int64
└──      goto #2
4 ─      goto #5
5return %2
) => Int64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions