+ optimize comparisons of constant pointers

git-svn-id: trunk@47031 -
This commit is contained in:
florian 2020-10-01 20:33:03 +00:00
parent af20b064ed
commit 65047cecdb

View File

@ -506,6 +506,7 @@ implementation
b : boolean;
cr, cl : Tconstexprint;
v2p, c2p, c1p, v1p: pnode;
p1,p2: TConstPtrUInt;
begin
result:=nil;
l1:=0;
@ -1330,6 +1331,33 @@ implementation
exit;
end;
if is_constpointernode(left) and is_constpointernode(right) then
begin
p1:=0;
p2:=0;
if left.nodetype=pointerconstn then
p1:=tpointerconstnode(left).value;
if right.nodetype=pointerconstn then
p2:=tpointerconstnode(right).value;
case nodetype of
equaln:
result:=cordconstnode.create(ord(p1=p2),bool8type,false);
unequaln:
result:=cordconstnode.create(ord(p1<>p2),bool8type,false);
gtn:
result:=cordconstnode.create(ord(p1>p2),bool8type,false);
ltn:
result:=cordconstnode.create(ord(p1<p2),bool8type,false);
gten:
result:=cordconstnode.create(ord(p1>=p2),bool8type,false);
lten:
result:=cordconstnode.create(ord(p1<=p2),bool8type,false);
else
Internalerror(2020100101);
end;
exit;
end;
{ slow simplifications }
if cs_opt_level2 in current_settings.optimizerswitches then
begin