anchor.diff:  %%  will allocate the lowest free X register for the variable.
   
   reserve_xregs(Blocks, Res) ->
  -    F = fun(L, #b_blk{is=Is,last=Last}, R) ->
  -                {Xs0,Used0} = reserve_terminator(L, Last, Blocks, R),
  -                reserve_xregs_is(reverse(Is), R, Xs0, Used0)
  -        end,
  -    beam_ssa:fold_po(F, Res, Blocks).
  -
  +    Ls = reverse(beam_ssa:rpo(Blocks)),
  +    reserve_xregs(Ls, Blocks, #{}, Res).
  +
  +reserve_xregs([L|Ls], Blocks, XsMap0, Res0) ->
  +    #b_blk{anno=Anno,is=Is0,last=Last} = map_get(L, Blocks),
  +
  +    %% Calculate mapping from variable name to the preferred
  +    %% register.
  +    Xs0 = reserve_terminator(L, Is0, Last, Blocks, XsMap0, Res0),
  +
  +    %% We need to figure out where the code generator will
  +    %% place instructions that will do a garbage collection.
  +    %% Insert 'gc' markers as pseudo-instructions in the
  +    %% instruction sequence.
  +    Is1 = reverse(Is0),
  +    Is2 = res_place_gc_instrs(Is1, []),
  +    Is = res_place_allocate(Anno, Is2),
  +
  +    %% Add register hints for variables that are defined
  +    %% in the (reversed) instruction sequence.
  +    {Res,Xs} = reserve_xregs_is(Is, Res0, Xs0, []),
  +
  +    XsMap = XsMap0#{L=>Xs},
  +    reserve_xregs(Ls, Blocks, XsMap, Res);
  +reserve_xregs([], _, _, Res) -> Res.
  +
  +%% Insert explicit 'gc' markers points where there will
  +%% be a garbage collection. (Note that the instruction
  +%% sequence passed to this function is reversed.)
  +
  +res_place_gc_instrs([#b_set{op=phi}=I|Is], Acc) ->
  +    res_place_gc_instrs(Is, [I|Acc]);
  +res_place_gc_instrs([#b_set{op=Op}=I|Is], Acc)
  +  when Op =:= call; Op =:= make_fun ->
  +    case Acc of
  +        [] ->
  +            res_place_gc_instrs(Is, [I|Acc]);
  +        [GC|_] when GC =:= gc; GC =:= test_heap ->
  +            res_place_gc_instrs(Is, [I,gc|Acc]);
  +        [_|_] ->
  +            res_place_gc_instrs(Is, [I,gc|Acc])
  +    end;
  +res_place_gc_instrs([#b_set{op=Op,args=Args}=I|Is], Acc0) ->
  +    case beam_ssa_codegen:classify_heap_need(Op, Args) of
  +        neutral ->
  +            case Acc0 of
  +                [test_heap|Acc] ->
  +                    res_place_gc_instrs(Is, [test_heap,I|Acc]);
  +                Acc ->
  +                    res_place_gc_instrs(Is, [I|Acc])
  +            end;
  +        {put,_} ->
  +            case Acc0 of
  +                [test_heap|Acc] ->
  +                    res_place_gc_instrs(Is, [test_heap,I|Acc]);
  +                Acc ->
  +                    res_place_gc_instrs(Is, [test_heap,I|Acc])
  +            end;
  +        _ ->
  +            res_place_gc_instrs(Is, [gc,I|Acc0])
  +    end;
  +res_place_gc_instrs([], Acc) ->
  +    %% Reverse and replace 'test_heap' markers with 'gc'.
  +    %% (The distinction is no longer useful.)
  +    res_place_gc_instrs_rev(Acc, []).
  +
  +res_place_gc_instrs_rev([test_heap|Is], [gc|_]=Acc) ->
  +    res_place_gc_instrs_rev(Is, Acc);
  +res_place_gc_instrs_rev([test_heap|Is], Acc) ->
  +    res_place_gc_instrs_rev(Is, [gc|Acc]);
  +res_place_gc_instrs_rev([gc|Is], [gc|_]=Acc) ->
  +    res_place_gc_instrs_rev(Is, Acc);
  +res_place_gc_instrs_rev([I|Is], Acc) ->
  +    res_place_gc_instrs_rev(Is, [I|Acc]);
  +res_place_gc_instrs_rev([], Acc) -> Acc.
  +
  +res_place_allocate(#{yregs:=_}, Is) ->
  +    %% There will be an 'allocate' instruction inserted here.
  +    Is ++ [gc];
  +res_place_allocate(#{}, Is) -> Is.
  +
  +reserve_xregs_is([gc|Is], Res, Xs0, Used) ->
  +    %% At this point, the code generator will place an instruction
  +    %% that does a garbage collection. We must prune the remembered
  +    %% registers.
  +    Xs = res_xregs_prune(Xs0, Used, Res),
  +    reserve_xregs_is(Is, Res, Xs, Used);
   reserve_xregs_is([#b_set{op=Op,dst=Dst,args=Args}=I|Is], Res0, Xs0, Used0) ->
  -    Xs1 = case is_gc_safe(I) of
  -              true ->
  -                  Xs0;
  -              false ->
  -                  %% There may be a garbage collection after executing this
  -                  %% instruction. We will need prune the list of preferred
  -                  %% X registers.
  -                  res_xregs_prune(Xs0, Used0, Res0)
  -          end,
  -    Res = reserve_xreg(Dst, Xs1, Res0),
  +    Res = reserve_xreg(Dst, Xs0, Res0),
       Used1 = ordsets:union(Used0, beam_ssa:used(I)),
       Used = ordsets:del_element(Dst, Used1),
       case Op of
  
positive.code: 
      %% Remove unsafe registers from the list of potential
      %% preferred registers.
      maps:filter(fun(_, {x,X}) -> X < NumSafe end, Xs).
  
  %%%
  %%% Register allocation using linear scan.
  
negative.code: reserve_xreg(V, Xs, Res) ->
      case Res of
          #{V:=_} ->
              %% Already reserved (but not as an X register).
              Res;
          #{} ->
              case Xs of
                  #{V:=X} ->
                      %% Add a hint that this specific X register is
                      %% preferred, unless it is already in use.
                      Res#{V=>{prefer,X}};
                  #{} ->
  