@@ -130,7 +130,7 @@ function simple_walk(compact::IncrementalCompact, @nospecialize(defssa#=::AnySSA
130130                return  defssa
131131            end 
132132            if  isa (def. val, SSAValue)
133-                 if  isa (defssa, OldSSAValue)  &&   ! already_inserted (compact, defssa)
133+                 if  is_old (compact, defssa)
134134                    defssa =  OldSSAValue (def. val. id)
135135                else 
136136                    defssa =  def. val
@@ -191,7 +191,7 @@ function walk_to_defs(compact::IncrementalCompact, @nospecialize(defssa), @nospe
191191                collect (Iterators. filter (1 : length (def. edges)) do  n
192192                    isassigned (def. values, n) ||  return  false 
193193                    val =  def. values[n]
194-                     if  isa (defssa, OldSSAValue ) &&  isa (val, SSAValue)
194+                     if  is_old (compact, defssa ) &&  isa (val, SSAValue)
195195                        val =  OldSSAValue (val. id)
196196                    end 
197197                    edge_typ =  widenconst (compact_exprtype (compact, val))
@@ -201,7 +201,7 @@ function walk_to_defs(compact::IncrementalCompact, @nospecialize(defssa), @nospe
201201            for  n in  possible_predecessors
202202                pred =  def. edges[n]
203203                val =  def. values[n]
204-                 if  isa (defssa, OldSSAValue ) &&  isa (val, SSAValue)
204+                 if  is_old (compact, defssa ) &&  isa (val, SSAValue)
205205                    val =  OldSSAValue (val. id)
206206                end 
207207                if  isa (val, AnySSAValue)
@@ -281,7 +281,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
281281            end 
282282            if  is_tuple_call (compact, def) &&  isa (field, Int) &&  1  <=  field <  length (def. args)
283283                lifted =  def. args[1 + field]
284-                 if  isa (leaf, OldSSAValue ) &&  isa (lifted, SSAValue)
284+                 if  is_old (compact, leaf ) &&  isa (lifted, SSAValue)
285285                    lifted =  OldSSAValue (lifted. id)
286286                end 
287287                if  isa (lifted, GlobalRef) ||  isa (lifted, Expr)
@@ -320,7 +320,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
320320                    compact[leaf] =  def
321321                end 
322322                lifted =  def. args[1 + field]
323-                 if  isa (leaf, OldSSAValue ) &&  isa (lifted, SSAValue)
323+                 if  is_old (compact, leaf ) &&  isa (lifted, SSAValue)
324324                    lifted =  OldSSAValue (lifted. id)
325325                end 
326326                if  isa (lifted, GlobalRef) ||  isa (lifted, Expr)
@@ -339,7 +339,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
339339                    #  N.B.: This can be a bit dangerous because it can lead to
340340                    #  infinite loops if we accidentally insert a node just ahead
341341                    #  of where we are
342-                     if  isa (leaf, OldSSAValue ) &&  (isa (field, Int) ||  isa (field, Symbol))
342+                     if  is_old (compact, leaf ) &&  (isa (field, Int) ||  isa (field, Symbol))
343343                        (isa (typ, DataType) &&  (! typ. abstract)) ||  return  nothing 
344344                        @assert  ! typ. mutable
345345                        #  If there's the potential for an undefref error on access, we cannot insert a getfield
@@ -425,6 +425,12 @@ struct LiftedPhi
425425    need_argupdate:: Bool 
426426end 
427427
428+ function  is_old (compact, @nospecialize (old_node_ssa))
429+     isa (old_node_ssa, OldSSAValue) && 
430+         ! is_pending (compact, old_node_ssa) && 
431+         ! already_inserted (compact, old_node_ssa)
432+ end 
433+ 
428434function  perform_lifting! (compact:: IncrementalCompact ,
429435        visited_phinodes:: Vector{Any} , @nospecialize (cache_key),
430436        lifting_cache:: IdDict{Pair{AnySSAValue, Any}, AnySSAValue} ,
@@ -455,7 +461,7 @@ function perform_lifting!(compact::IncrementalCompact,
455461            isassigned (old_node. values, i) ||  continue 
456462            val =  old_node. values[i]
457463            orig_val =  val
458-             if  isa (old_node_ssa, OldSSAValue)  &&   ! is_pending (compact, old_node_ssa)  &&   ! already_inserted (compact, old_node_ssa) &&  isa (val, SSAValue)
464+             if  is_old (compact, old_node_ssa) &&  isa (val, SSAValue)
459465                val =  OldSSAValue (val. id)
460466            end 
461467            if  isa (val, Union{NewSSAValue, SSAValue, OldSSAValue})
@@ -688,10 +694,14 @@ function getfield_elim_pass!(ir::IRCode, domtree::DomTree)
688694        compact[idx] =  val ===  nothing  ?  nothing  :  val. x
689695    end 
690696
691-     #  Copy the use count, `finish` may modify it and for our predicate
692-     #  below we need it consistent with the state of the IR here.
697+ 
698+     non_dce_finish! (compact)
699+     #  Copy the use count, `simple_dce!` may modify it and for our predicate
700+     #  below we need it consistent with the state of the IR here (after tracking
701+     #  phi node arguments, but before dce).
693702    used_ssas =  copy (compact. used_ssas)
694-     ir =  finish (compact)
703+     simple_dce! (compact)
704+     ir =  complete (compact)
695705    #  Now go through any mutable structs and see which ones we can eliminate
696706    for  (idx, (intermediaries, defuse)) in  defuses
697707        intermediaries =  collect (intermediaries)
0 commit comments