Explorar el Código

* convert <real x>*<real x> into sqr(<real x>), it might reduces register
pressure and/or memory accesses without a drawback

git-svn-id: trunk@18252 -

florian hace 14 años
padre
commit
e796a878ca
Se han modificado 1 ficheros con 41 adiciones y 28 borrados
  1. 41 28
      compiler/nadd.pas

+ 41 - 28
compiler/nadd.pas

@@ -748,35 +748,48 @@ implementation
              exit;
           end;
 
-        { the comparison is might be expensive and the nodes are usually only
-          equal if some previous optimizations were done so don't check
-          this simplification always
-        }
-        if (cs_opt_level2 in current_settings.optimizerswitches) and
-          is_boolean(left.resultdef) and is_boolean(right.resultdef) and
-          { since the expressions might have sideeffects, we may only remove them
-            if short boolean evaluation is turned on }
-          (nf_short_bool in flags) then
-            begin
-              if left.isequal(right) then
-                begin
-                  case nodetype of
-                    andn,orn:
-                      begin
-                        result:=left;
-                        left:=nil;
-                        exit;
-                      end;
-                    {
-                    xorn:
-                      begin
-                        result:=cordconstnode.create(0,resultdef,true);
-                        exit;
-                      end;
-                    }
+        { slow simplifications }
+        if (cs_opt_level2 in current_settings.optimizerswitches) then
+          begin
+            { the comparison is might be expensive and the nodes are usually only
+              equal if some previous optimizations were done so don't check
+              this simplification always
+            }
+            if is_boolean(left.resultdef) and is_boolean(right.resultdef) and
+            { since the expressions might have sideeffects, we may only remove them
+              if short boolean evaluation is turned on }
+            (nf_short_bool in flags) then
+              begin
+                if left.isequal(right) then
+                  begin
+                    case nodetype of
+                      andn,orn:
+                        begin
+                          result:=left;
+                          left:=nil;
+                          exit;
+                        end;
+                      {
+                      xorn:
+                        begin
+                          result:=cordconstnode.create(0,resultdef,true);
+                          exit;
+                        end;
+                      }
+                    end;
                   end;
-                end;
-            end;
+              end;
+
+            { using sqr(x) for reals instead of x*x might reduces register pressure and/or
+              memory accesses while sqr(<real>) has no drawback }
+            if is_real(left.resultdef) and is_real(left.resultdef) and
+              left.isequal(right) then
+              begin
+                result:=cinlinenode.create(in_sqr_real,false,left);
+                left:=nil;
+                exit;
+              end;
+          end;
       end;