Hi,

I am looking at the code generated for a function, and I feel there is often
unnecessary movement of data between registers, especially r15.  Is there
some reason while small calcuations always seem to use r15?  I'm compiling
with -O2.

In this particular code snippet, I have a variable "muxSelect" defined as a
"word" (typedef for unsigned int).  The code includes:

void foo(void) {
    word i, j;
    word nextMux = (muxSelect + 1) & 0x07;

    // More code, using nextMux and muxSelect

    muxSelect = nextMux;
}

The "nextMux = (muxSelect + 1) & 0x07" line is compiled to:
    mov &muxSelect, r9                // Puts muxSelect in a register, as it
will be used later
    mov r9, r15
    add #llo(1), r15
    mov r15, r7                             // Why go through r15, and not
just use r7 directly?
    and #llo(7), r7

I've seen this sort of thing on several occasions - r15 is used as a scratch
register, when the original calculation could have been done directly in the
destination register.  Am I missing something here, or is there the
possibility of optomising this more?

Just for fun, I added the "-frename-registers" flag to the compile.  The
result was that r8 was used instead of r15, but basically the same code was
produced.

mvh.

David



Reply via email to