* use new shl/shr constant folding (of r26295) only if forinline is set

* explicitly simplify tree after constant propagation

git-svn-id: trunk@26311 -
This commit is contained in:
florian 2013-12-29 14:09:03 +00:00
parent be3749301f
commit 27f6fd1c2c
4 changed files with 46 additions and 25 deletions

1
.gitattributes vendored
View File

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

View File

@ -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);
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;
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;
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);

View File

@ -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);

View File

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