mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-22 07:09:29 +02:00
+ New optimization: Comparisions with evaluate to true or false if the
constant is outside the range of type bounds of the left expression. I.e. "if a>0" evaluates to true if a is declared with type 1..10, as all legal values of a are greater than zero. git-svn-id: trunk@7603 -
This commit is contained in:
parent
8bae130fcb
commit
60dee7fcf0
@ -173,7 +173,6 @@ implementation
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ both are int constants }
|
||||
if (
|
||||
(
|
||||
@ -382,7 +381,92 @@ implementation
|
||||
end;
|
||||
result:=t;
|
||||
exit;
|
||||
end;
|
||||
end
|
||||
{Match against the ranges, i.e.:
|
||||
var a:1..10;
|
||||
begin
|
||||
if a>0 then
|
||||
... always evaluates to true. (DM)}
|
||||
else if is_constintnode(left) and (right.resultdef.typ=orddef)
|
||||
{workaround for u64bit bugs} and (Torddef(right.resultdef).ordtype<>u64bit) then
|
||||
begin
|
||||
t:=nil;
|
||||
lv:=Tordconstnode(left).value;
|
||||
with Torddef(right.resultdef) do
|
||||
case nodetype of
|
||||
ltn:
|
||||
if lv<low then
|
||||
t:=Cordconstnode.create(1,booltype,true)
|
||||
else if lv>=high then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
lten:
|
||||
if lv<=low then
|
||||
t:=Cordconstnode.create(1,booltype,true)
|
||||
else if lv>high then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
gtn:
|
||||
if lv<=low then
|
||||
t:=Cordconstnode.create(0,booltype,true)
|
||||
else if lv>high then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
gten :
|
||||
if lv<low then
|
||||
t:=Cordconstnode.create(0,booltype,true)
|
||||
else if lv>=high then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
equaln:
|
||||
if (lv<low) or (lv>high) then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
unequaln:
|
||||
if (lv<low) or (lv>high) then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
end;
|
||||
if t<>nil then
|
||||
begin
|
||||
result:=t;
|
||||
exit;
|
||||
end
|
||||
end
|
||||
else if (left.resultdef.typ=orddef) and is_constintnode(right)
|
||||
{workaround for u64bit bugs} and (Torddef(left.resultdef).ordtype<>u64bit) then
|
||||
begin
|
||||
t:=nil;
|
||||
rv:=Tordconstnode(right).value;
|
||||
with Torddef(left.resultdef) do
|
||||
case nodetype of
|
||||
ltn:
|
||||
if high<rv then
|
||||
t:=Cordconstnode.create(1,booltype,true)
|
||||
else if low>=rv then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
lten:
|
||||
if high<=rv then
|
||||
t:=Cordconstnode.create(1,booltype,true)
|
||||
else if low>rv then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
gtn:
|
||||
if high<=rv then
|
||||
t:=Cordconstnode.create(0,booltype,true)
|
||||
else if low>rv then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
gten:
|
||||
if high<rv then
|
||||
t:=Cordconstnode.create(0,booltype,true)
|
||||
else if low>=rv then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
equaln:
|
||||
if (rv<low) or (rv>high) then
|
||||
t:=Cordconstnode.create(0,booltype,true);
|
||||
unequaln:
|
||||
if (rv<low) or (rv>high) then
|
||||
t:=Cordconstnode.create(1,booltype,true);
|
||||
end;
|
||||
if t<>nil then
|
||||
begin
|
||||
result:=t;
|
||||
exit;
|
||||
end
|
||||
end;
|
||||
|
||||
{ Add,Sub,Mul with constant 0 or 1? }
|
||||
if is_constintnode(right) and is_integer(left.resultdef) then
|
||||
|
Loading…
Reference in New Issue
Block a user