This one is a case of inefficiency - this sequence of instructions appears in the compilation of the HexToBin function in the Classes unit (-O3, but with the peephole optimizer turned off):

    ...
    movzbw    (%rcx),%r9w
    andw    $15,%r9w
    movswl    %r9w,%r9d
    movl    %r9d,%ebx
    ...

When the peephole optimizer is turned on and the compiler has DEBUG_AOPTOBJ defined:

    ...
# Peephole Optimization: var15
# Peephole Optimization: var15
# Peephole Optimization: var15
# Peephole Optimization: var15
    movzbw    (%rcx),%r9w
    andw    $15,%r9w
    movswl    %r9w,%r9d
    movl    %r9d,%ebx
    ...

"var15" is the optimisation (also one of the risky infinite loop ones) that analyses a "movzbw/andw" pair and changes the "andw #, %regw" instruction to "andw (# and $FF), %regw".  It performs this optimisation during all four iterations of Pass 1, even though 15 and $FF = 15 in this case and nothing actually changes. Meanwhile, though unrelated, there appears to be no peephole optimisation to change "movswl %r9w,%r9d; movl %r9d,%ebx" to "movswl %r9w,%ebx".  Theoretically, in this instance, the use of R9 can be dropped completely and only RBX used, but that's another story.

I'm still looking at ways to improve the peephole optimizer, specifically reducing the number of passes where possible, but I figure I need to work on one function at a time.  OptPass1MOV and its sister functions could use a lot of refactoring.  I'll submit small patches over time that are easier to verify.

Gareth aka. Kit

_______________________________________________
fpc-devel maillist  -  [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to