[fpc-devel] optimizing the peephole optimizer?

Martin lazarus at mfriebe.de
Sun Jan 19 18:01:40 CET 2014


As I just looked through some of the code, I found the following.

compiler\i386\popt386.pas

                 case taicpu(p).opcode Of
....
// line  1122
                   A_MOV:

has several "if" statements, some concatenated with else, but some 
independent.

                       if (taicpu(p).oper[1]^.typ = top_reg) and
                          (getsupreg(taicpu(p).oper[1]^.reg) in [RS_EAX, 
RS_EBX, RS_ECX, RS_EDX, RS_ESI, RS_EDI]) and
                          GetNextInstruction(p, hp1) and
                          (tai(hp1).typ = ait_instruction) and
....
                       else
                         if (taicpu(p).oper[0]^.typ = top_reg) and
                            (taicpu(p).oper[1]^.typ = top_reg) and
                            GetNextInstruction(p,hp1) and
                            (tai(hp1).typ = ait_instruction) and
....
// NO ELSE
                       if GetNextInstruction(p, hp1) and
....
// NO ELSE
                       if GetNextInstruction(p, hp1) and
MatchInstruction(hp1,A_BTS,A_BTR,[Taicpu(p).opsize]) and
...
...

In each of them GetNextInstruction(p, hp1) could be executed.

If I counted correct, it can be called up to 6 times for each a_mov.
On the other hand:
- no code in this case block, is ever executed, if it does not succeed.
- It will always be executed at least once

So it would probably be better to have this once at the start of the 
A_MOV block.


If that makes sense, I can check other blocks for similar issues.





More information about the fpc-devel mailing list