瀏覽代碼

* improved firstcomplex() in case one of the two nodes does not need any
floating point registers, or in case they both need just as many

git-svn-id: trunk@11840 -

Jonas Maebe 17 年之前
父節點
當前提交
23a219ae59
共有 1 個文件被更改,包括 25 次插入2 次删除
  1. 25 2
      compiler/ncgutil.pas

+ 25 - 2
compiler/ncgutil.pas

@@ -213,6 +213,9 @@ implementation
 
 
     procedure firstcomplex(p : tbinarynode);
+      var
+        fcl, fcr: longint;
+        ncl, ncr: longint;
       begin
          { always calculate boolean AND and OR from left to right }
          if (p.nodetype in [orn,andn]) and
@@ -222,8 +225,28 @@ implementation
                internalerror(200709253);
            end
          else
-           if node_resources_fpu(p.right)>node_resources_fpu(p.left) then
-             p.swapleftright;
+           begin
+             fcl:=node_resources_fpu(p.left);
+             fcr:=node_resources_fpu(p.right);
+             ncl:=node_complexity(p.left);
+             ncr:=node_complexity(p.right);
+             { We swap left and right if
+                a) right needs more floating point registers than left, and
+                   left needs more than 0 floating point registers (if it
+                   doesn't need any, swapping won't change the floating
+                   point register pressure)
+                b) both left and right need an equal amount of floating
+                   point registers or right needs no floating point registers,
+                   and in addition right has a higher complexity than left
+                   (+- needs more integer registers, but not necessarily)
+             }
+             if ((fcr>fcl) and
+                 (fcl>0)) or
+                (((fcr=fcl) or
+                  (fcr=0)) and
+                 (ncr>ncl)) then
+               p.swapleftright
+           end;
       end;