Browse Source

* at -O3 optimization level, convert "i:=not i" and "i:=-i" to the new
in_not_assign_x and in_neg_assign_x inline nodes, which may generate better
code on certain cpus (such as x86)

git-svn-id: trunk@35758 -

nickysn 8 năm trước cách đây
mục cha
commit
3616627d0b
1 tập tin đã thay đổi với 25 bổ sung0 xóa
  1. 25 0
      compiler/nld.pas

+ 25 - 0
compiler/nld.pas

@@ -668,6 +668,31 @@ implementation
                     taddnode(right).left:=nil;
                     exit;
                   end;
+                { replace i:=not i  by in_not_assign_x(i)
+                          i:=-i     by in_neg_assign_x(i)
+                  todo: for some integer types, there are extra implicit
+                        typecasts inserted by the compiler; this code should be
+                        updated to handle them as well }
+                if (right.nodetype in [notn,unaryminusn]) and
+                  (tunarynode(right).left.isequal(left)) and
+
+                  is_integer(tunarynode(right).left.resultdef) and
+
+                  ((localswitches*[cs_check_overflow,cs_check_range])=[]) and
+                  ((right.localswitches*[cs_check_overflow,cs_check_range])=[]) and
+                  valid_for_var(tunarynode(right).left,false) and
+                  not(might_have_sideeffects(tunarynode(right).left)) then
+                  begin
+                    if right.nodetype=notn then
+                      newinlinenodetype:=in_not_assign_x
+                    else
+                      newinlinenodetype:=in_neg_assign_x;
+                    result:=cinlinenode.createintern(
+                      newinlinenodetype,false,tunarynode(right).left);
+                    left:=nil;
+                    tunarynode(right).left:=nil;
+                    exit;
+                  end;
               end;
           end;
       end;