Переглянути джерело

* factored out PostPeepholeOptCmp
+ use PostPeepholeOptCmp for x86_64

git-svn-id: trunk@37549 -

florian 7 роки тому
батько
коміт
a7ea7fb569
3 змінених файлів з 19 додано та 11 видалено
  1. 2 11
      compiler/i386/aoptcpu.pas
  2. 15 0
      compiler/x86/aoptx86.pas
  3. 2 0
      compiler/x86_64/aoptcpu.pas

+ 2 - 11
compiler/i386/aoptcpu.pas

@@ -1309,17 +1309,8 @@ begin
                     end;
                 end;
               A_CMP:
-                begin
-                  if (taicpu(p).oper[0]^.typ = top_const) and
-                     (taicpu(p).oper[0]^.val = 0) and
-                     (taicpu(p).oper[1]^.typ = top_reg) then
-                   {change "cmp $0, %reg" to "test %reg, %reg"}
-                    begin
-                      taicpu(p).opcode := A_TEST;
-                      taicpu(p).loadreg(0,taicpu(p).oper[1]^.reg);
-                      continue;
-                    end;
-                end;
+                if PostPeepholeOptCmp(p) then
+                  Continue;
               A_MOV:
                 PostPeepholeOptMov(p);
               A_MOVZX:

+ 15 - 0
compiler/x86/aoptx86.pas

@@ -73,6 +73,7 @@ unit aoptx86;
         function OptPass2Jcc(var p : tai) : boolean;
 
         procedure PostPeepholeOptMov(const p : tai);
+        function PostPeepholeOptCmp(var p : tai) : Boolean;
 
         procedure OptReferences;
       end;
@@ -2668,6 +2669,20 @@ unit aoptx86;
     end;
 
 
+    function TX86AsmOptimizer.PostPeepholeOptCmp(var p : tai) : Boolean;
+      begin
+        Result:=false;
+        { change "cmp $0, %reg" to "test %reg, %reg" }
+        if MatchOpType(taicpu(p),top_const,top_reg) and
+           (taicpu(p).oper[0]^.val = 0) then
+          begin
+            taicpu(p).opcode := A_TEST;
+            taicpu(p).loadreg(0,taicpu(p).oper[1]^.reg);
+            Result:=true;
+          end;
+      end;
+
+
     procedure TX86AsmOptimizer.OptReferences;
       var
         p: tai;

+ 2 - 0
compiler/x86_64/aoptcpu.pas

@@ -142,6 +142,8 @@ uses
               case taicpu(p).opcode of
                 A_MOV:
                   PostPeepholeOptMov(p);
+                A_CMP:
+                  Result:=PostPeepholeOptCmp(p);
               end;
             end;
         end;