Przeglądaj źródła

Ensure register to be eliminated is de-allocated before applying optimization LdsMov2Lds.

ccrause 1 rok temu
rodzic
commit
dd858f37aa
1 zmienionych plików z 9 dodań i 7 usunięć
  1. 9 7
      compiler/avr/aoptcpu.pas

+ 9 - 7
compiler/avr/aoptcpu.pas

@@ -444,12 +444,16 @@ Implementation
       }
       else if not(cs_opt_level3 in current_settings.optimizerswitches) and
       (taicpu(p).oper[0]^.typ=top_reg) and
+      assigned(FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.Previous))) and
       (GetNextInstruction(p,hp1)) and MatchInstruction(hp1,A_LDS) and
       (taicpu(hp1).oper[0]^.typ=top_reg) and
+      assigned(FindRegAllocBackward(taicpu(hp1).oper[0]^.reg,tai(hp1.Previous))) and
       (GetNextInstruction(hp1, hp2)) and MatchInstruction(hp2,A_MOV) and
       (taicpu(hp2).oper[1]^.reg=taicpu(p).oper[0]^.reg) and
+      assigned(FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp2.Next))) and
       (GetNextInstruction(hp2, hp3)) and MatchInstruction(hp3,A_MOV) and
-      (taicpu(hp3).oper[1]^.reg=taicpu(hp1).oper[0]^.reg) then
+      (taicpu(hp3).oper[1]^.reg=taicpu(hp1).oper[0]^.reg) and
+      assigned(FindRegDeAlloc(taicpu(hp1).oper[0]^.reg,tai(hp3.Next))) then
       begin
         DebugMsg('Peephole LdsLdsMovMov2LdsLds performed', p);
 
@@ -498,21 +502,19 @@ Implementation
       (not RegModifiedBetween(taicpu(p).oper[0]^.reg, p, hp1)) and
       (not RegUsedBetween(taicpu(hp1).oper[0]^.reg, p, hp1)) then
       begin
-        DebugMsg('Peephole LdsMov2Lds performed', p);
-
         alloc:=FindRegAllocBackward(taicpu(p).oper[0]^.reg,tai(p.Previous));
         dealloc:=FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp1.Next));
         if assigned(alloc) and assigned(dealloc) then
           begin
+            DebugMsg('Peephole LdsMov2Lds performed', p);
             asml.Remove(alloc);
             alloc.Free;
             asml.Remove(dealloc);
             dealloc.Free;
+            taicpu(p).oper[0]^.reg:=taicpu(hp1).oper[0]^.reg;
+            RemoveInstruction(hp1);
+            result:=true;
           end;
-
-        taicpu(p).oper[0]^.reg:=taicpu(hp1).oper[0]^.reg;
-        RemoveInstruction(hp1);
-        result:=true;
       end;
     end;