浏览代码

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

git-svn-id: trunk@3868 -

Jonas Maebe 19 年之前
父节点
当前提交
5fa53a1a8c
共有 3 个文件被更改,包括 28 次插入0 次删除
  1. 1 0
      .gitattributes
  2. 12 0
      compiler/nmat.pas
  3. 15 0
      tests/test/cg/tmoddiv1.pp

+ 1 - 0
.gitattributes

@@ -5933,6 +5933,7 @@ tests/test/cg/tloadvmt.pp svneol=native#text/plain
 tests/test/cg/tlohi.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/tmanypar.pp svneol=native#text/plain
 tests/test/cg/tmoddiv.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/tmoddiv2.pp svneol=native#text/plain
 tests/test/cg/tmul3264.pp svneol=native#text/plain
 tests/test/cg/tmul3264.pp svneol=native#text/plain
 tests/test/cg/tneg.pp svneol=native#text/plain
 tests/test/cg/tneg.pp svneol=native#text/plain

+ 12 - 0
compiler/nmat.pas

@@ -107,6 +107,18 @@ implementation
       begin
       begin
         result:=nil;
         result:=nil;
 
 
+        if is_constintnode(right) then
+          begin
+            if tordconstnode(right).value = 1 then
+              case nodetype of
+                modn:
+                  result := cordconstnode.create(0,left.resulttype,true);
+                divn:
+                  result := left.getcopy;
+              end;
+              exit;
+          end;
+
         if is_constintnode(right) and is_constintnode(left) then
         if is_constintnode(right) and is_constintnode(left) then
           begin
           begin
             rd:=torddef(right.resulttype.def);
             rd:=torddef(right.resulttype.def);

+ 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.
+