فهرست منبع

* optimize intvar*(-1) to -intvar

git-svn-id: trunk@9418 -
Jonas Maebe 17 سال پیش
والد
کامیت
814e983c98
1فایلهای تغییر یافته به همراه15 افزوده شده و 1 حذف شده
  1. 15 1
      compiler/nadd.pas

+ 15 - 1
compiler/nadd.pas

@@ -439,7 +439,7 @@ implementation
                 end
                 end
             end;
             end;
 
 
-        { Add,Sub,Mul with constant 0 or 1?  }
+        { Add,Sub,Mul with constant 0, 1 or -1?  }
         if is_constintnode(right) and is_integer(left.resultdef) then
         if is_constintnode(right) and is_integer(left.resultdef) then
           begin
           begin
             if tordconstnode(right).value = 0 then
             if tordconstnode(right).value = 0 then
@@ -457,6 +457,13 @@ implementation
                   muln:
                   muln:
                    result := left.getcopy;
                    result := left.getcopy;
                 end;
                 end;
+              end
+            else if tordconstnode(right).value = -1 then
+              begin
+                case nodetype of
+                  muln:
+                   result := cunaryminusnode.create(left.getcopy);
+                end;
               end;
               end;
             if assigned(result) then
             if assigned(result) then
               exit;
               exit;
@@ -480,6 +487,13 @@ implementation
                   muln:
                   muln:
                    result := right.getcopy;
                    result := right.getcopy;
                 end;
                 end;
+              end
+            else if tordconstnode(left).value = -1 then
+              begin
+                case nodetype of
+                  muln:
+                   result := cunaryminusnode.create(right.getcopy);
+                end;
               end;
               end;
             if assigned(result) then
             if assigned(result) then
               exit;
               exit;