A method for arithmetic expression optimization includes receiving an
operator and at least one operand of a first instruction defined for a
first processor having a first base. The method also includes converting
the first instruction to a second instruction optimized for a second
processor having a second base smaller than the first base when the at
least one operand does not carry potential overflow beyond the second
base or when the operator is insensitive to overflow. The method also
includes converting instructions in an instruction chain to a wider base
larger than the second base and smaller or equal to the first base when
the at least one operand carries potential overflow beyond the second
base and when the operator is sensitive to overflow. The chain is bounded
by the second instruction and a third instruction that has been
previously optimized and is the source of the potential overflow.