Browse Source

+ PXorPXor2PXor optimization

git-svn-id: trunk@45430 -
florian 5 years ago
parent
commit
9b54588d75
3 changed files with 35 additions and 0 deletions
  1. 3 0
      compiler/i386/aoptcpu.pas
  2. 29 0
      compiler/x86/aoptx86.pas
  3. 3 0
      compiler/x86_64/aoptcpu.pas

+ 3 - 0
compiler/i386/aoptcpu.pas

@@ -141,6 +141,9 @@ unit aoptcpu;
                   Result:=OptPass1And(p);
                 A_CMP:
                   Result:=OptPass1Cmp(p);
+                A_VPXOR,
+                A_PXOR:
+                  Result:=OptPass1PXor(p);
                 A_FLD:
                   Result:=OptPass1FLD(p);
                 A_FSTP,A_FISTP:

+ 29 - 0
compiler/x86/aoptx86.pas

@@ -130,6 +130,7 @@ unit aoptx86;
         function OptPass1FSTP(var p : tai) : boolean;
         function OptPass1FLD(var p : tai) : boolean;
         function OptPass1Cmp(var p : tai) : boolean;
+        function OptPass1PXor(var p : tai) : boolean;
 
         function OptPass2MOV(var p : tai) : boolean;
         function OptPass2Imul(var p : tai) : boolean;
@@ -3949,6 +3950,34 @@ unit aoptx86;
      end;
 
 
+   function TX86AsmOptimizer.OptPass1PXor(var p: tai): boolean;
+     var
+       hp1: tai;
+     begin
+       {
+         remove the second (v)pxor from
+
+           (v)pxor reg,reg
+           ...
+           (v)pxor reg,reg
+       }
+       Result:=false;
+       if MatchOperand(taicpu(p).oper[0]^,taicpu(p).oper[1]^) and
+         MatchOpType(taicpu(p),top_reg,top_reg) and
+         GetNextInstructionUsingReg(p,hp1,taicpu(p).oper[0]^.reg) and
+         MatchInstruction(taicpu(hp1),taicpu(p).opcode,[taicpu(p).opsize]) and
+         MatchOperand(taicpu(p).oper[0]^,taicpu(hp1).oper[0]^) and
+         MatchOperand(taicpu(hp1).oper[0]^,taicpu(hp1).oper[1]^) then
+         begin
+           DebugMsg(SPeepholeOptimization + 'PXorPXor2PXor done',hp1);
+           asml.Remove(hp1);
+           hp1.Free;
+           Result:=true;
+           Exit;
+         end;
+     end;
+
+
    function TX86AsmOptimizer.OptPass2MOV(var p : tai) : boolean;
 
      function IsXCHGAcceptable: Boolean; inline;

+ 3 - 0
compiler/x86_64/aoptcpu.pas

@@ -127,6 +127,9 @@ uses
                   result:=OptPass1FLD(p);
                 A_CMP:
                   result:=OptPass1Cmp(p);
+                A_VPXOR,
+                A_PXOR:
+                  Result:=OptPass1PXor(p);
                 else
                   ;
               end;