mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-05-02 05:16:04 +02:00
* optimize <expr> and/or <expr> if they are equal and boolean
git-svn-id: trunk@14714 -
This commit is contained in:
parent
cf5c42b596
commit
a58e07df38
@ -744,6 +744,35 @@ implementation
|
||||
exit;
|
||||
end;
|
||||
|
||||
{ the comparison is might be expensive and the nodes are usually only
|
||||
equal if some previous optimizations were done so don't check
|
||||
this simplification always
|
||||
}
|
||||
if (cs_opt_level2 in current_settings.optimizerswitches) and
|
||||
is_boolean(left.resultdef) and is_boolean(right.resultdef) and
|
||||
{ since the expressions might have sideeffects, we may only remove them
|
||||
if short boolean evaluation is turned on }
|
||||
(nf_short_bool in flags) then
|
||||
begin
|
||||
if left.isequal(right) then
|
||||
begin
|
||||
case nodetype of
|
||||
andn,orn:
|
||||
begin
|
||||
result:=left;
|
||||
left:=nil;
|
||||
exit;
|
||||
end;
|
||||
{
|
||||
xorn:
|
||||
begin
|
||||
result:=cordconstnode.create(0,resultdef,true);
|
||||
exit;
|
||||
end;
|
||||
}
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user