@@ -684,33 +684,29 @@ function type_annotate!(sv::InferenceState, run_optimizer::Bool)
684684 nslots = length (slotflags)
685685 undefs = fill (false , nslots)
686686
687- # eliminate GotoIfNot if either of branch target is unreachable
688- if run_optimizer
689- for idx = 1 : nexpr
690- stmt = body[idx]
691- if isa (stmt, GotoIfNot) && widenconst (argextype (stmt. cond, src, sv. sptypes)) === Bool
692- # replace live GotoIfNot with:
693- # - GotoNode if the fallthrough target is unreachable
694- # - no-op if the branch target is unreachable
695- if ! was_reached (sv, idx+ 1 )
696- body[idx] = GotoNode (stmt. dest)
697- elseif ! was_reached (sv, stmt. dest)
698- body[idx] = nothing
699- end
700- end
701- end
702- end
703-
704- # this statement traversal does three things:
687+ # this statement traversal does five things:
705688 # 1. introduce temporary `TypedSlot`s that are supposed to be replaced with π-nodes later
706689 # 2. mark used-undef slots (required by the `slot2reg` conversion)
707690 # 3. mark unreached statements for a bulk code deletion (see issue #7836)
708691 # 4. widen `Conditional`s and remove `NOT_FOUND` from `ssavaluetypes`
709- # NOTE: because of 4, `was_reached` will no longer be available after this point
692+ # NOTE because of this, `was_reached` will no longer be available after this point
693+ # 5. eliminate GotoIfNot if either branch target is unreachable
710694 changemap = nothing # initialized if there is any dead region
711695 for i = 1 : nexpr
712696 expr = body[i]
713697 if was_reached (sv, i)
698+ if run_optimizer
699+ if isa (expr, GotoIfNot) && widenconst (argextype (expr. cond, src, sv. sptypes)) === Bool
700+ # 5: replace this live GotoIfNot with:
701+ # - GotoNode if the fallthrough target is unreachable
702+ # - no-op if the branch target is unreachable
703+ if ! was_reached (sv, i+ 1 )
704+ expr = GotoNode (expr. dest)
705+ elseif ! was_reached (sv, expr. dest)
706+ expr = nothing
707+ end
708+ end
709+ end
714710 body[i] = annotate_slot_load! (undefs, i, sv, expr) # 1&2
715711 ssavaluetypes[i] = widenconditional (ssavaluetypes[i]) # 4
716712 else # i.e. any runtime execution will never reach this statement
0 commit comments