Dead Code Elimination

        /* Original Assembly instruction:
         *   addw %eax, %ebx
         */
        tmp = ebx; // original value
        ebx = ebx + eax;
        zf = ebx == 0; // zero flag
        nf = ebx < 0; // negative flag
        of = ... // overflow flag
        cf = ... // carry flag
        pf = ... // parity flag

        /* Original Assembly instruction:
         *   addw %eax, %ebx
         */
        ebx = ebx + eax;

Motivation

When compiling a program the compiler chooses the sequence of processor instructions that best mimic the behavior specified by the source code. Most processor instructions, however, have several hard-coded side-effects that are often unintended by the compiler. The best example is given by the flag registers, which are modified after every arithmetic processor instruction, but their value is typically only used on conditional jumps. Therefore a semantic translation of an arithmetic processor instruction often results in several unused flag assignments, which can and should be removed for better code understanding.

Mechanics