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

"div 1" wrongly)

git-svn-id: trunk@3868 -
This commit is contained in:
Jonas Maebe 2006-06-15 15:53:43 +00:00
parent a49a8ba774
commit 5fa53a1a8c
3 changed files with 28 additions and 0 deletions

1
.gitattributes vendored
View File

@ -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/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/tmul3264.pp svneol=native#text/plain
tests/test/cg/tneg.pp svneol=native#text/plain

View File

@ -107,6 +107,18 @@ implementation
begin
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
begin
rd:=torddef(right.resulttype.def);

15
tests/test/cg/tmoddiv1.pp Normal file
View File

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