mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-16 14:09:41 +02:00
* 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:
parent
be3749301f
commit
27f6fd1c2c
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -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/tarmshift.pp svneol=native#text/plain
|
||||||
tests/test/opt/tcaseopt1.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/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/tcse1.pp svneol=native#text/plain
|
||||||
tests/test/opt/tcse2.pp svneol=native#text/plain
|
tests/test/opt/tcse2.pp svneol=native#text/plain
|
||||||
tests/test/opt/tcse3.pp svneol=native#text/plain
|
tests/test/opt/tcse3.pp svneol=native#text/plain
|
||||||
|
@ -580,32 +580,39 @@ implementation
|
|||||||
{ constant folding }
|
{ constant folding }
|
||||||
if is_constintnode(left) and is_constintnode(right) then
|
if is_constintnode(left) and is_constintnode(right) then
|
||||||
begin
|
begin
|
||||||
{ x86 wraps around }
|
if forinline then
|
||||||
{ shl/shr are unsigned operations, so cut off upper bits }
|
begin
|
||||||
case resultdef.size of
|
{ shl/shr are unsigned operations, so cut off upper bits }
|
||||||
1:
|
case resultdef.size of
|
||||||
begin
|
1:
|
||||||
rvalue:=tordconstnode(right).value and byte($7);
|
begin
|
||||||
lvalue:=tordconstnode(left).value and byte($ff);
|
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;
|
end;
|
||||||
2:
|
end
|
||||||
begin
|
else
|
||||||
rvalue:=tordconstnode(right).value and byte($f);
|
begin
|
||||||
lvalue:=tordconstnode(left).value and word($ffff);
|
rvalue:=tordconstnode(right).value;
|
||||||
end;
|
lvalue:=tordconstnode(left).value;
|
||||||
4:
|
end;
|
||||||
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;
|
|
||||||
case nodetype of
|
case nodetype of
|
||||||
shrn:
|
shrn:
|
||||||
result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);
|
result:=create_simplified_ord_const(lvalue shr rvalue,resultdef,forinline);
|
||||||
|
@ -311,15 +311,20 @@ unit optconstprop;
|
|||||||
function do_optconstpropagate(var rootnode: tnode): tnode;
|
function do_optconstpropagate(var rootnode: tnode): tnode;
|
||||||
var
|
var
|
||||||
changed: boolean;
|
changed: boolean;
|
||||||
|
runsimplify : Boolean;
|
||||||
begin
|
begin
|
||||||
{$ifdef DEBUG_CONSTPROP}
|
{$ifdef DEBUG_CONSTPROP}
|
||||||
writeln('************************ before constant propagation ***************************');
|
writeln('************************ before constant propagation ***************************');
|
||||||
printnode(rootnode);
|
printnode(rootnode);
|
||||||
{$endif DEBUG_CONSTPROP}
|
{$endif DEBUG_CONSTPROP}
|
||||||
|
runsimplify:=false;
|
||||||
repeat
|
repeat
|
||||||
changed:=false;
|
changed:=false;
|
||||||
foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
|
foreachnodestatic(pm_postandagain, rootnode, @propagate, @changed);
|
||||||
|
runsimplify:=runsimplify or changed;
|
||||||
until changed=false;
|
until changed=false;
|
||||||
|
if runsimplify then
|
||||||
|
doinlinesimplify(rootnode);
|
||||||
{$ifdef DEBUG_CONSTPROP}
|
{$ifdef DEBUG_CONSTPROP}
|
||||||
writeln('************************ after constant propagation ***************************');
|
writeln('************************ after constant propagation ***************************');
|
||||||
printnode(rootnode);
|
printnode(rootnode);
|
||||||
|
8
tests/test/opt/tconstprop1.pp
Normal file
8
tests/test/opt/tconstprop1.pp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const
|
||||||
|
l = 1 shl 63;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if l<>$8000000000000000 then
|
||||||
|
halt(1);
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user