Parcourir la source

+ fold "a shl n1 shl n2" and "a shr n1 shr n2" into "a shl (n1+n2)" and "a shr (n1+n2)", resolves #39629

florian il y a 3 ans
Parent
commit
02289d1f5b
1 fichiers modifiés avec 9 ajouts et 0 suppressions
  1. 9 0
      compiler/nmat.pas

+ 9 - 0
compiler/nmat.pas

@@ -775,6 +775,15 @@ implementation
               begin
                 result:=left;
                 left:=nil;
+              end
+            { optimize "a shl n1 shl n2" and "a shr n1 shr n2" }
+            else if (nodetype=left.nodetype) and is_constintnode(tshlshrnode(left).right) and
+              { do not overflow the variable being shifted }
+              (tordconstnode(right).value+tordconstnode(tshlshrnode(left).right).value<tshlshrnode(left).left.resultdef.size*8) then
+              begin
+                result:=left;
+                left:=nil;
+                tordconstnode(tshlshrnode(result).right).value:=tordconstnode(tshlshrnode(result).right).value+tordconstnode(right).value;
               end;
           end
         else if is_constintnode(left) then