fpc/tests/webtbs/tw38267a.pp
florian 97abf6b495 * 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 -
2021-01-01 15:26:13 +00:00

44 lines
1.3 KiB
ObjectPascal

{ %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.