Răsfoiți Sursa

+ TX86AsmOptimizer.OptPass1OP

git-svn-id: trunk@36365 -
florian 8 ani în urmă
părinte
comite
22956c4393
3 a modificat fișierele cu 61 adăugiri și 0 ștergeri
  1. 6 0
      compiler/i386/aoptcpu.pas
  2. 50 0
      compiler/x86/aoptx86.pas
  3. 5 0
      compiler/x86_64/aoptcpu.pas

+ 6 - 0
compiler/i386/aoptcpu.pas

@@ -1263,6 +1263,12 @@ begin
                   A_VADDSS:
                     if OptPass1VOP(p) then
                       continue;
+                  A_MULSD,
+                  A_MULSS,
+                  A_ADDSD,
+                  A_ADDSS:
+                    if OptPass1OP(p) then
+                      continue;
                   A_MOVAPD,
                   A_MOVAPS:
                     if OptPass1MOVAP(p) then

+ 50 - 0
compiler/x86/aoptx86.pas

@@ -64,6 +64,7 @@ unit aoptx86;
         function OptPass1Movx(var p : tai) : boolean;
         function OptPass1MOVAP(var p : tai) : boolean;
         function OptPass1MOVXX(var p : tai) : boolean;
+        function OptPass1OP(const p : tai) : boolean;
 
         function OptPass2MOV(var p : tai) : boolean;
         function OptPass2Imul(var p : tai) : boolean;
@@ -1064,6 +1065,15 @@ unit aoptx86;
         hp1 : tai;
       begin
         result:=false;
+        { replace
+            V<Op>X   %mreg1,%mreg2,%mreg3
+            VMovX    %mreg3,%mreg4
+            dealloc  %mreg3
+
+            by
+            V<Op>X   %mreg1,%mreg2,%mreg4
+          ?
+        }
         if GetNextInstruction(p,hp1) and
           { we mix single and double opperations here because we assume that the compiler
             generates vmovapd only after double operations and vmovaps only after single operations }
@@ -1077,6 +1087,7 @@ unit aoptx86;
              ) then
               begin
                 taicpu(p).loadoper(2,taicpu(hp1).oper[1]^);
+                DebugMsg('PeepHole Optimization VOpVmov2VOp done',p);
                 asml.Remove(hp1);
                 hp1.Free;
                 result:=true;
@@ -1670,6 +1681,45 @@ unit aoptx86;
       end;
 
 
+    function TX86AsmOptimizer.OptPass1OP(const p : tai) : boolean;
+      var
+        TmpUsedRegs : TAllUsedRegs;
+        hp1 : tai;
+      begin
+        result:=false;
+        { replace
+            <Op>X    %mreg1,%mreg2  // Op in [ADD,MUL]
+            MovX     %mreg2,%mreg1
+            dealloc  %mreg2
+
+            by
+            <Op>X    %mreg2,%mreg1
+          ?
+        }
+        if GetNextInstruction(p,hp1) and
+          { we mix single and double opperations here because we assume that the compiler
+            generates vmovapd only after double operations and vmovaps only after single operations }
+          MatchInstruction(hp1,A_MOVAPD,A_MOVAPS,[S_NO]) and
+          MatchOperand(taicpu(p).oper[1]^,taicpu(hp1).oper[0]^) and
+          MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[1]^) and
+          (taicpu(p).oper[0]^.typ=top_reg) then
+          begin
+            CopyUsedRegs(TmpUsedRegs);
+            UpdateUsedRegs(TmpUsedRegs, tai(p.next));
+            if not(RegUsedAfterInstruction(taicpu(p).oper[1]^.reg,hp1,TmpUsedRegs)
+             ) then
+              begin
+                taicpu(p).loadoper(0,taicpu(hp1).oper[0]^);
+                taicpu(p).loadoper(1,taicpu(hp1).oper[1]^);
+                DebugMsg('PeepHole Optimization OpMov2Op done',p);
+                asml.Remove(hp1);
+                hp1.Free;
+                result:=true;
+              end;
+          end;
+      end;
+
+
     function TX86AsmOptimizer.OptPass2MOV(var p : tai) : boolean;
       var
        TmpUsedRegs : TAllUsedRegs;

+ 5 - 0
compiler/x86_64/aoptcpu.pas

@@ -87,6 +87,11 @@ uses
               A_VADDSD,
               A_VADDSS:
                 result:=OptPass1VOP(p);
+              A_MULSD,
+              A_MULSS,
+              A_ADDSD,
+              A_ADDSS:
+                result:=OptPass1OP(p);
               A_VMOVSD,
               A_VMOVSS,
               A_MOVSD,