mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-12-08 20:57:24 +01:00
* first part of fixing #38267: do not bail out early during constant folding
if the constant is 1 or -1 git-svn-id: trunk@47933 -
This commit is contained in:
parent
8311837468
commit
97abf6b495
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -18620,6 +18620,7 @@ tests/webtbs/tw38225.pp svneol=native#text/pascal
|
|||||||
tests/webtbs/tw38238.pp svneol=native#text/pascal
|
tests/webtbs/tw38238.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw38249.pp svneol=native#text/pascal
|
tests/webtbs/tw38249.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw38259.pp svneol=native#text/pascal
|
tests/webtbs/tw38259.pp svneol=native#text/pascal
|
||||||
|
tests/webtbs/tw38267a.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw3827.pp svneol=native#text/plain
|
tests/webtbs/tw3827.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw3829.pp svneol=native#text/plain
|
tests/webtbs/tw3829.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw3833.pp svneol=native#text/plain
|
tests/webtbs/tw3833.pp svneol=native#text/plain
|
||||||
|
|||||||
@ -708,9 +708,9 @@ implementation
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
{ Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1? }
|
{ Add,Sub,Mul,Or,Xor,Andn with constant 0, 1 or -1? }
|
||||||
if is_constintnode(right) and (is_integer(left.resultdef) or is_pointer(left.resultdef)) then
|
if is_constintnode(right) and (is_integer(left.resultdef) or is_pointer(left.resultdef)) then
|
||||||
begin
|
begin
|
||||||
if tordconstnode(right).value = 0 then
|
if (tordconstnode(right).value = 0) and (nodetype in [addn,subn,orn,xorn,andn,muln]) then
|
||||||
begin
|
begin
|
||||||
case nodetype of
|
case nodetype of
|
||||||
addn,subn,orn,xorn:
|
addn,subn,orn,xorn:
|
||||||
@ -725,24 +725,13 @@ implementation
|
|||||||
;
|
;
|
||||||
end;
|
end;
|
||||||
end
|
end
|
||||||
else if tordconstnode(right).value = 1 then
|
|
||||||
begin
|
else if (tordconstnode(right).value = 1) and (nodetype=muln) then
|
||||||
case nodetype of
|
result := left.getcopy
|
||||||
muln:
|
|
||||||
result := left.getcopy;
|
else if (tordconstnode(right).value = -1) and (nodetype=muln) then
|
||||||
else
|
result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef)
|
||||||
;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else if tordconstnode(right).value = -1 then
|
|
||||||
begin
|
|
||||||
case nodetype of
|
|
||||||
muln:
|
|
||||||
result := ctypeconvnode.create_internal(cunaryminusnode.create(left.getcopy),left.resultdef);
|
|
||||||
else
|
|
||||||
;
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
{ try to fold
|
{ try to fold
|
||||||
op op
|
op op
|
||||||
/ \ / \
|
/ \ / \
|
||||||
|
|||||||
43
tests/webtbs/tw38267a.pp
Normal file
43
tests/webtbs/tw38267a.pp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
{ %OPT=-O3 }
|
||||||
|
{$goto on}
|
||||||
|
label start0, end0, start1, end1;
|
||||||
|
|
||||||
|
var
|
||||||
|
x: int16;
|
||||||
|
|
||||||
|
begin
|
||||||
|
x := random(2);
|
||||||
|
writeln('x := ', x);
|
||||||
|
writeln;
|
||||||
|
|
||||||
|
start0:
|
||||||
|
x :=
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+x;
|
||||||
|
end0:
|
||||||
|
writeln('x := 1 + 1 + ...100 times ... + x, x = ', x, ': ');
|
||||||
|
writeln(SizeUint(CodePointer(@end0) - CodePointer(@start0)), ' b of code');
|
||||||
|
{ hundred is actually arbitrarily chosen but should be sufficient for all targets
|
||||||
|
to show that constant folding works }
|
||||||
|
if SizeUint(CodePointer(@end0) - CodePointer(@start0))>100 then
|
||||||
|
halt(1);
|
||||||
|
writeln;
|
||||||
|
|
||||||
|
start1:
|
||||||
|
x := x+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+
|
||||||
|
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1;
|
||||||
|
end1:
|
||||||
|
writeln('x := x + 1 + 1 + ...100 times ..., x = ', x, ': ');
|
||||||
|
{ hundred is actually arbitrarily chosen but should be sufficient for all targets
|
||||||
|
to show that constant folding works }
|
||||||
|
writeln(SizeUint(CodePointer(@end1) - CodePointer(@start1)), ' b of code');
|
||||||
|
if SizeUint(CodePointer(@end1) - CodePointer(@start1))>100 then
|
||||||
|
halt(2);
|
||||||
|
writeln('ok');
|
||||||
|
end.
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user