[fpc-devel] optimizing the peephole optimizer?

Florian Klämpfl florian at freepascal.org
Tue Jan 21 22:20:49 CET 2014


Am 19.01.2014 18:01, schrieb Martin:
> 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.

I guess the idea is to catch typical code sequences in one go, see also
the comment in 1243:
{ Next instruction is also a MOV ? }

It is still on my todo list though to update the peephole optimizer and
make a common one for i386 and x86_64 ...




More information about the fpc-devel mailing list