Pārlūkot izejas kodu

+ optimize '0 shl x' and '0 shr x' to 0

git-svn-id: trunk@36041 -
nickysn 8 gadi atpakaļ
vecāks
revīzija
de1e0c405e
1 mainītis faili ar 22 papildinājumiem un 0 dzēšanām
  1. 22 0
      compiler/nmat.pas

+ 22 - 0
compiler/nmat.pas

@@ -702,6 +702,28 @@ implementation
                 result:=left;
                 left:=nil;
               end;
+          end
+        else if is_constintnode(left) then
+          begin
+            lvalue:=tordconstnode(left).value;
+            { shl/shr are unsigned operations, so cut off upper bits }
+            case resultdef.size of
+              1:
+                lvalue:=tordconstnode(left).value and byte($ff);
+              2:
+                lvalue:=tordconstnode(left).value and word($ffff);
+              4:
+                lvalue:=tordconstnode(left).value and dword($ffffffff);
+              8:
+                lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
+              else
+                internalerror(2013122301);
+            end;
+            { '0 shl x' and '0 shr x' are 0 }
+            if (lvalue=0) and
+               ((cs_opt_level4 in current_settings.optimizerswitches) or
+                not might_have_sideeffects(right)) then
+              result:=cordconstnode.create(0,resultdef,true);
           end;
       end;