Browse Source

* factored out V<Op> optimizations into OptPass1VOP
* call OptPass1VOP also for i386

git-svn-id: trunk@33878 -

florian 9 years ago
parent
commit
20807f4148
3 changed files with 40 additions and 20 deletions
  1. 10 0
      compiler/i386/aoptcpu.pas
  2. 28 0
      compiler/x86/aoptx86.pas
  3. 2 20
      compiler/x86_64/aoptcpu.pas

+ 10 - 0
compiler/i386/aoptcpu.pas

@@ -2149,6 +2149,16 @@ begin
                   A_VMOVAPD:
                     if OptPass1VMOVAP(p) then
                       continue;
+                  A_VDIVSD,
+                  A_VDIVSS,
+                  A_VSUBSD,
+                  A_VSUBSS,
+                  A_VMULSD,
+                  A_VMULSS,
+                  A_VADDSD,
+                  A_VADDSS:
+                    if OptPass1VOP(p) then
+                      continue;
                 end;
             end; { if is_jmp }
           end;

+ 28 - 0
compiler/x86/aoptx86.pas

@@ -40,6 +40,7 @@ unit aoptx86;
       protected
         procedure PostPeepholeOptMov(const p : tai);
         function OptPass1VMOVAP(var p : tai) : boolean;
+        function OptPass1VOP(const p : tai) : boolean;
       end;
 
     function MatchInstruction(const instr: tai; const op: TAsmOp; const opsize: topsizes): boolean;
@@ -294,6 +295,33 @@ unit aoptx86;
       end;
 
 
+    function TX86AsmOptimizer.OptPass1VOP(const p : tai) : boolean;
+      var
+        TmpUsedRegs : TAllUsedRegs;
+        hp1 : tai;
+      begin
+        result:=false;
+        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_VMOVAPD,A_VMOVAPS,[S_NO]) and
+          MatchOperand(taicpu(p).oper[2]^,taicpu(hp1).oper[0]^) and
+          (taicpu(hp1).oper[1]^.typ=top_reg) then
+          begin
+            CopyUsedRegs(TmpUsedRegs);
+            UpdateUsedRegs(TmpUsedRegs, tai(p.next));
+            if not(RegUsedAfterInstruction(taicpu(hp1).oper[0]^.reg,hp1,TmpUsedRegs)
+             ) then
+              begin
+                taicpu(p).loadoper(2,taicpu(hp1).oper[1]^);
+                asml.Remove(hp1);
+                hp1.Free;
+                result:=true;
+              end;
+          end;
+      end;
+
+
     procedure TX86AsmOptimizer.PostPeepholeOptMov(const p : tai);
       begin
        if MatchOperand(taicpu(p).oper[0]^,0) and

+ 2 - 20
compiler/x86_64/aoptcpu.pas

@@ -587,27 +587,10 @@ begin
         A_VMULSS,
         A_VADDSD,
         A_VADDSS:
-          begin
-            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_VMOVAPD,A_VMOVAPS,[S_NO]) and
-              MatchOperand(taicpu(p).oper[2]^,taicpu(hp1).oper[0]^) and
-              (taicpu(hp1).oper[1]^.typ=top_reg) then
-              begin
-                CopyUsedRegs(TmpUsedRegs);
-                UpdateUsedRegs(TmpUsedRegs, tai(p.next));
-                If not(RegUsedAfterInstruction(taicpu(hp1).oper[0]^.reg,hp1,TmpUsedRegs)) then
-                  begin
-                    taicpu(p).loadoper(2,taicpu(hp1).oper[1]^);
-                    asml.Remove(hp1);
-                    hp1.Free;
-                  end;
-              end;
-          end;
-        end;
+          result:=OptPass1VOP(p);
       end;
     end;
+  end;
 end;
 
 
@@ -625,7 +608,6 @@ end;
         end;
       end;
 
-
 begin
   casmoptimizer := TCpuAsmOptimizer;
 end.