Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-01

tNode.isequal optimization

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dariusz Mazur

Hi
I've read some code of compiler (try to understand how it work) and I notice, that tNode.isequal is invoked very often but has not optimal (by me) implementation

my proposition is (one assigned less):

   function tnode.isequal(p : tnode) : boolean;
     begin
        if assigned(self) then   begin
            result:=(assigned(p) and
                (p.classtype=classtype) and
                (p.nodetype=nodetype) and
                (flags*flagsequal=p.flags*flagsequal) and
                docompare(p));
        end  else
          result:=not assigned(p);
     end;
(*    *original*
        isequal:=   (not assigned(self) and not assigned(p)) or
          (assigned(self) and assigned(p) and
           { optimized subclasses have the same nodetype as their        }
           { superclass (for compatibility), so also check the classtype
(JM) }
           (p.classtype=classtype) and
           (p.nodetype=nodetype) and
           (flags*flagsequal=p.flags*flagsequal) and
           docompare(p));

*)

and second:

make isequal inlined, then in function

   function tunarynode.docompare(p : tnode) : boolean;
     begin
        docompare:=(inherited docompare(p) and
          (not assigned(left) or left.isequal(tunarynode(p).left))
        );
     end;

compiler can fold two equal node : not assigned(left) or ((assigned(p) and
{ optimized subclasses have the same nodetype as their } { superclass (for compatibility), so also check the classtype (JM) }
(p.classtype=classtype) and
(p.nodetype=nodetype) and
(flags*flagsequal=p.flags*flagsequal) and

           docompare(p));

Will those optimization give better code?
Can compiler remove unnecessary nodes in boolean operation after inline unfolding?

Darek

Reply by email