Răsfoiți Sursa

Enabled do_spill_replace.
Added some more peephole optimizations, and fixed normalize_ref.

git-svn-id: branches/laksen/spc32@33833 -

Jeppe Johansen 9 ani în urmă
părinte
comite
a8ea387a27
3 a modificat fișierele cu 80 adăugiri și 8 ștergeri
  1. 71 2
      compiler/spc32/aoptcpu.pas
  2. 8 5
      compiler/spc32/cgcpu.pas
  3. 1 1
      compiler/spc32/rgcpu.pas

+ 71 - 2
compiler/spc32/aoptcpu.pas

@@ -261,6 +261,43 @@ Implementation
                       result:=true;
                     end
                   {
+                    turn
+                      ld #x
+                      ldu #y
+                      ldX #0
+                    into
+                      nul
+                      ldu #y+$8000
+                      ldX #x
+                  }
+                  else if (taicpu(p).ops=1) and
+                     (taicpu(p).oper[0]^.typ=top_ref) and
+                     (taicpu(p).oper[0]^.ref^.refaddr=addr_lo16) and
+                     GetNextInstruction(p,hp1) and
+                     (hp1.typ=ait_instruction) and
+                     (taicpu(hp1).opcode in [A_LDU]) and
+                     (taicpu(hp1).ops=1) and
+                     (taicpu(hp1).oper[0]^.typ=top_ref) and
+                     (taicpu(hp1).oper[0]^.ref^.refaddr=addr_hi16) and
+                     GetNextInstruction(hp1,hp2) and
+                     (hp2.typ=ait_instruction) and
+                     (taicpu(hp2).opcode in [A_LDB,A_LDH,A_LDW]) and
+                     (taicpu(hp2).ops=1) and
+                     (taicpu(hp2).oper[0]^.typ=top_const) and
+                     (taicpu(hp2).oper[0]^.val=0) then
+                    begin
+                      DebugMsg('LdLduLdx2NulLduLdx', p);
+
+                      inc(taicpu(hp1).oper[0]^.ref^.offset, $8000);
+
+                      taicpu(hp2).loadref(0, taicpu(p).oper[0]^.ref^);
+
+                      taicpu(p).ops:=0;
+                      taicpu(p).opcode:=A_NUL;
+
+                      result:=true;
+                    end
+                  {
                     turn
                       ld 0
                     into
@@ -474,13 +511,13 @@ Implementation
                      (taicpu(hp1).opcode=A_NUL) and
                      GetNextInstruction(hp1,hp2) and
                      (hp1.typ=ait_instruction) and
-                     (taicpu(hp2).opcode=A_LDW) and
+                     (taicpu(hp2).opcode in [A_LDW,A_LDH,A_LDB]) and
                      (taicpu(hp2).ops=1) and
                      (taicpu(hp2).oper[0]^.typ=top_reg) and
                      (taicpu(hp2).oper[0]^.reg=taicpu(p).oper[0]^.reg) and
                      Assigned(FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp2.next))) then
                     begin
-                      DebugMsg('StNulLdw2Ldw', p);
+                      DebugMsg('StNulLdx2Ldx', p);
 
                       alloc:=FindRegAllocBackward(taicpu(p).oper[0]^.reg, tai(p.Previous));
                       dealloc:=FindRegDeAlloc(taicpu(p).oper[0]^.reg,tai(hp2.next));
@@ -778,6 +815,8 @@ Implementation
                           dealloc.free;
                         end;
 
+                      DebugMsg('NulStOp2Op0', p);
+
                       AsmL.Remove(hp1);
                       hp1.free;
 
@@ -796,6 +835,9 @@ Implementation
                      (hp1.typ=ait_instruction) and
                      (taicpu(hp1).opcode in [A_NUL,A_LD]) then
                     begin
+
+                      DebugMsg('Dup nul removed', p);
+
                       asml.remove(p);
                       p.free;
                       p:=hp1;
@@ -813,11 +855,38 @@ Implementation
                      (hp1.typ=ait_instruction) and
                      (taicpu(hp1).opcode in [A_ADD]) then
                     begin
+                      DebugMsg('NulAdd2Ld', p);
+
+                      asml.remove(p);
+                      p.free;
+                      p:=hp1;
+
+                      taicpu(p).opcode:=A_LD;
+
+                      result:=true;
+                    end
+                  {
+                    turn
+                      nul
+                      sub #x
+                    into
+                      ld #x
+                  }
+                  else if GetNextInstruction(p,hp1) and
+                     (hp1.typ=ait_instruction) and
+                     (taicpu(hp1).opcode in [A_SUB]) and
+                     (taicpu(hp1).ops=1) and
+                     (taicpu(hp1).oper[0]^.typ=top_const) and
+                     (abs(taicpu(hp1).oper[0]^.val)<$8000) then
+                    begin
+                      DebugMsg('NulSub2Ld', p);
+
                       asml.remove(p);
                       p.free;
                       p:=hp1;
 
                       taicpu(p).opcode:=A_LD;
+                      taicpu(p).oper[0]^.val:=-taicpu(p).oper[0]^.val;
 
                       result:=true;
                     end;

+ 8 - 5
compiler/spc32/cgcpu.pas

@@ -520,7 +520,7 @@ unit cgcpu;
     function tcgspc32.normalize_ref(list:TAsmList;ref: treference) : treference;
       var
         tmpref : treference;
-        tmpreg : tregister;
+        tmpreg , b: tregister;
         l : tasmlabel;
       begin
         Result:=ref;
@@ -545,13 +545,16 @@ unit cgcpu;
           begin
             tmpreg:=getaddressregister(list);
 
+            b:=result.base;
+            result.base:=NR_NO;
+
             result.refaddr:=addr_lo16;
             list.concat(taicpu.op_ref(A_LD,Result));
             result.refaddr:=addr_hi16;
             list.concat(taicpu.op_ref(A_LDU,Result));
 
-            if result.base<>NR_NO then
-              list.concat(taicpu.op_reg(A_ADD,result.base));
+            if b<>NR_NO then
+              list.concat(taicpu.op_reg(A_ADD,b));
 
             list.concat(taicpu.op_reg(A_ST,tmpreg));
 
@@ -999,9 +1002,9 @@ unit cgcpu;
               list.concat(taicpu.op_const(A_PUSH,longword(regs)));
 
             cnt:=0;
-            for reg:=RS_R0 to RS_LR do
+            {for reg:=RS_R0 to RS_LR do
               if reg in regs then
-                inc(cnt);
+                inc(cnt);}
 
             if (current_procinfo.framepointer<>NR_STACK_POINTER_REG) or (LocalSize>0) then
               begin

+ 1 - 1
compiler/spc32/rgcpu.pas

@@ -96,7 +96,7 @@ unit rgcpu;
         b : byte;
       begin
         result:=false;
-        //if abs(spilltemp.offset)>127 then
+        if abs(spilltemp.offset)>$7FFF then
           exit;
 
         { Replace 'mov  dst,orgreg' with 'ldr  dst,spilltemp'