瀏覽代碼

* factor out TARMAsmOptimizer.USxtOp2Op

florian 2 年之前
父節點
當前提交
5cbb36f218
共有 2 個文件被更改,包括 43 次插入30 次删除
  1. 2 29
      compiler/aarch64/aoptcpu.pas
  2. 41 1
      compiler/armgen/aoptarm.pas

+ 2 - 29
compiler/aarch64/aoptcpu.pas

@@ -720,8 +720,6 @@ Implementation
     var
       hp1: tai;
       GetNextInstructionUsingReg_hp1: Boolean;
-      so: tshifterop;
-      opoffset: Integer;
     begin
       Result:=false;
       if GetNextInstructionUsingReg(p,hp1,taicpu(p).oper[0]^.reg) then
@@ -771,33 +769,8 @@ Implementation
               taicpu(hp1).loadReg(1,taicpu(p).oper[1]^.reg);
               result:=RemoveCurrentP(p);
             end
-          else if (taicpu(p).ops=2) and
-            ((MatchInstruction(hp1, [A_ADD,A_SUB], [C_None], [PF_None,PF_S]) and
-            (taicpu(hp1).ops=3) and
-             MatchOperand(taicpu(hp1).oper[2]^, taicpu(p).oper[0]^.reg) and
-             not(MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg))) or
-             (MatchInstruction(hp1, [A_CMP,A_CMN], [C_None], [PF_None]) and
-             (taicpu(hp1).ops=2) and
-             MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg))
-            ) and
-            RegEndofLife(taicpu(p).oper[0]^.reg,taicpu(hp1)) and
-            { reg1 might not be modified inbetween }
-            not(RegModifiedBetween(taicpu(p).oper[1]^.reg,p,hp1)) then
-            begin
-              DebugMsg('Peephole SxtwOp2Op done', p);
-              AllocRegBetween(taicpu(p).oper[1]^.reg,p,hp1,UsedRegs);
-              if MatchInstruction(hp1, [A_CMP,A_CMN], [C_None], [PF_None]) then
-                opoffset:=0
-              else
-                opoffset:=1;
-              taicpu(hp1).loadReg(opoffset+1,taicpu(p).oper[1]^.reg);
-              taicpu(hp1).ops:=opoffset+3;
-              shifterop_reset(so);
-              so.shiftmode:=SM_SXTW;
-              so.shiftimm:=0;
-              taicpu(hp1).loadshifterop(opoffset+2,so);
-              result:=RemoveCurrentP(p);
-            end
+          else if USxtOp2Op(p,hp1,SM_SXTW) then
+            Result:=true
           else if RemoveSuperfluousMove(p, hp1, 'SxtwMov2Data') then
             Result:=true;
         end;

+ 41 - 1
compiler/armgen/aoptarm.pas

@@ -44,7 +44,9 @@ Type
     function RemoveSuperfluousMove(const p: tai; movp: tai; const optimizer: string): boolean;
     function RedundantMovProcess(var p: tai; var hp1: tai): boolean;
     function GetNextInstructionUsingReg(Current: tai; out Next: tai; const reg: TRegister): Boolean;
-
+{$ifdef AARCH64}
+    function USxtOp2Op(var p, hp1: tai; shiftmode: tshiftmode): Boolean;
+{$endif AARCH64}
     function OptPreSBFXUBFX(var p: tai): Boolean;
 
     function OptPass1UXTB(var p: tai): Boolean;
@@ -194,6 +196,44 @@ Implementation
     end;
 
 
+{$ifdef AARCH64}
+  function TARMAsmOptimizer.USxtOp2Op(var p,hp1: tai; shiftmode: tshiftmode): Boolean;
+    var
+      so: tshifterop;
+      opoffset: Integer;
+    begin
+      Result:=false;
+      if (taicpu(p).ops=2) and
+        ((MatchInstruction(hp1, [A_ADD,A_SUB], [C_None], [PF_None,PF_S]) and
+        (taicpu(hp1).ops=3) and
+         MatchOperand(taicpu(hp1).oper[2]^, taicpu(p).oper[0]^.reg) and
+         not(MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg))) or
+         (MatchInstruction(hp1, [A_CMP,A_CMN], [C_None], [PF_None]) and
+         (taicpu(hp1).ops=2) and
+         MatchOperand(taicpu(hp1).oper[1]^, taicpu(p).oper[0]^.reg))
+        ) and
+        RegEndofLife(taicpu(p).oper[0]^.reg,taicpu(hp1)) and
+        { reg1 might not be modified inbetween }
+        not(RegModifiedBetween(taicpu(p).oper[1]^.reg,p,hp1)) then
+        begin
+          DebugMsg('Peephole '+gas_op2str[taicpu(p).opcode]+gas_op2str[taicpu(hp1).opcode]+'2'+gas_op2str[taicpu(hp1).opcode]+' done', p);
+          AllocRegBetween(taicpu(p).oper[1]^.reg,p,hp1,UsedRegs);
+          if MatchInstruction(hp1, [A_CMP,A_CMN], [C_None], [PF_None]) then
+            opoffset:=0
+          else
+            opoffset:=1;
+          taicpu(hp1).loadReg(opoffset+1,taicpu(p).oper[1]^.reg);
+          taicpu(hp1).ops:=opoffset+3;
+          shifterop_reset(so);
+          so.shiftmode:=shiftmode;
+          so.shiftimm:=0;
+          taicpu(hp1).loadshifterop(opoffset+2,so);
+          result:=RemoveCurrentP(p);
+        end;
+    end;
+{$endif AARCH64}
+
+
   function TARMAsmOptimizer.GetNextInstructionUsingReg(Current: tai;
     Out Next: tai; const reg: TRegister): Boolean;
     var