Bläddra i källkod

* optimize away "x mod 1" and "x div 1" + test (ppc code generator handled
"div 1" wrongly)

git-svn-id: branches/fixes_2_0@3869 -

Jonas Maebe 19 år sedan
förälder
incheckning
394eccf1e0
3 ändrade filer med 28 tillägg och 0 borttagningar
  1. 1 0
      .gitattributes
  2. 12 0
      compiler/nmat.pas
  3. 15 0
      tests/test/cg/tmoddiv1.pp

+ 1 - 0
.gitattributes

@@ -5312,6 +5312,7 @@ tests/test/cg/tloadvmt.pp svneol=native#text/plain
 tests/test/cg/tlohi.pp svneol=native#text/plain
 tests/test/cg/tmanypar.pp svneol=native#text/plain
 tests/test/cg/tmoddiv.pp svneol=native#text/plain
+tests/test/cg/tmoddiv1.pp svneol=native#text/plain
 tests/test/cg/tmoddiv2.pp svneol=native#text/plain
 tests/test/cg/tneg.pp svneol=native#text/plain
 tests/test/cg/tnot.pp svneol=native#text/plain

+ 12 - 0
compiler/nmat.pas

@@ -139,6 +139,18 @@ implementation
                  { recover }
                  rv:=1;
                end;
+
+             if (rv = 1) then
+               begin
+                 case nodetype of
+                   modn:
+                     result := cordconstnode.create(0,left.resulttype,true);
+                   divn:
+                     result := left.getcopy;
+                 end;
+                 exit;
+               end;
+
              if is_constintnode(left) then
                begin
                  lv:=tordconstnode(left).value;

+ 15 - 0
tests/test/cg/tmoddiv1.pp

@@ -0,0 +1,15 @@
+var j,k : integer;
+
+begin
+     k:=4;
+     if (k div 1 <> 4) then
+       halt(1);
+     j := k div 1;
+     writeln(k div 1, ' ',j);
+     if (k div 1 <> 4) or
+        (j <> 4)  then
+       halt(1);
+     if (k mod 1) <> 0 then
+       halt(2);
+end.
+