Explorar el Código

* use new shl/shr constant folding (of r26295) only if forinline is set
* explicitly simplify tree after constant propagation

git-svn-id: trunk@26311 -

florian hace 11 años
padre
commit
27f6fd1c2c
Se han modificado 4 ficheros con 46 adiciones y 25 borrados
  1. 1 0
      .gitattributes
  2. 32 25
      compiler/nmat.pas
  3. 5 0
      compiler/optconstprop.pas
  4. 8 0
      tests/test/opt/tconstprop1.pp

+ 1 - 0
.gitattributes

@@ -10841,6 +10841,7 @@ tests/test/opt/tarmsa1.pp svneol=native#text/plain
 tests/test/opt/tarmshift.pp svneol=native#text/plain
 tests/test/opt/tcaseopt1.pp svneol=native#text/plain
 tests/test/opt/tcmov.pp svneol=native#text/plain
+tests/test/opt/tconstprop1.pp svneol=native#text/pascal
 tests/test/opt/tcse1.pp svneol=native#text/plain
 tests/test/opt/tcse2.pp svneol=native#text/plain
 tests/test/opt/tcse3.pp svneol=native#text/plain

+ 32 - 25
compiler/nmat.pas

@@ -580,32 +580,39 @@ implementation
         { constant folding }
         if is_constintnode(left) and is_constintnode(right) then
           begin
-             { x86 wraps around }
-             { shl/shr are unsigned operations, so cut off upper bits }
-             case resultdef.size of
-               1:
-                 begin
-                   rvalue:=tordconstnode(right).value and byte($7);
-                   lvalue:=tordconstnode(left).value and byte($ff);
-                 end;
-               2:
-                 begin
-                   rvalue:=tordconstnode(right).value and byte($f);
-                   lvalue:=tordconstnode(left).value and word($ffff);
-                 end;
-               4:
-                 begin
-                   rvalue:=tordconstnode(right).value and byte($1f);
-                   lvalue:=tordconstnode(left).value and dword($ffffffff);
-                 end;
-               8:
-                 begin
-                   rvalue:=tordconstnode(right).value and byte($3f);
-                   lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
+             if forinline then
+               begin
+                 { shl/shr are unsigned operations, so cut off upper bits }
+                 case resultdef.size of
+                   1:
+                     begin
+                       rvalue:=tordconstnode(right).value and byte($7);
+                       lvalue:=tordconstnode(left).value and byte($ff);
+                     end;
+                   2:
+                     begin
+                       rvalue:=tordconstnode(right).value and byte($f);
+                       lvalue:=tordconstnode(left).value and word($ffff);
+                     end;
+                   4:
+                     begin
+                       rvalue:=tordconstnode(right).value and byte($1f);
+                       lvalue:=tordconstnode(left).value and dword($ffffffff);
+                     end;
+                   8:
+                     begin
+                       rvalue:=tordconstnode(right).value and byte($3f);
+                       lvalue:=tordconstnode(left).value and qword($ffffffffffffffff);
+                     end;
+                   else
+                     internalerror(2013122301);
                  end;
-               else
-                 internalerror(2013122301);
-             end;
+               end
+             else
+               begin
+                 rvalue:=tordconstnode(right).value;
+                 lvalue:=tordconstnode(left).value;
+               end;
              case nodetype of
                 shrn:
                   result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);

+ 5 - 0
compiler/optconstprop.pas

@@ -311,15 +311,20 @@ unit optconstprop;
     function do_optconstpropagate(var rootnode: tnode): tnode;
       var
         changed: boolean;
+        runsimplify : Boolean;
       begin
 {$ifdef DEBUG_CONSTPROP}
         writeln('************************ before constant propagation ***************************');
         printnode(rootnode);
 {$endif DEBUG_CONSTPROP}
+        runsimplify:=false;
         repeat
           changed:=false;
           foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
+          runsimplify:=runsimplify or changed;
         until changed=false;
+        if runsimplify then
+          doinlinesimplify(rootnode);
 {$ifdef DEBUG_CONSTPROP}
         writeln('************************ after constant propagation ***************************');
         printnode(rootnode);

+ 8 - 0
tests/test/opt/tconstprop1.pp

@@ -0,0 +1,8 @@
+const
+  l = 1 shl 63;
+
+begin
+  if l<>$8000000000000000 then
+    halt(1);
+end.
+