Integer Promotion Elimination on Abstract Syntax Tree

In the C programming language standard, there are rules for implicit type conversions, including integer promotion rules. These rules, as well as the explicit type conversions imposed by the coder, may result in redundant code for 8-bit MCUs. However, code size is critical for the programs running in embedded systems, since smaller code size often means less consumption of ROM as well as energy, and thus more competitiveness for IC manufacturers. This paper presents a novel algorithm to eliminate redundant computations arising from unnecessary type conversions. Our algorithm employed the scheme of grammar attribute, and achieved remarkable performance in optimizing the code. Besides, using the scheme of grammar attribute, our algorithm is flexible and scalable to cover more syntactic elements of any programming language syntactically similar to C. Our experiment showed it achieved a reduction in code size of 36.1 percent with other traditional compiler optimization disabled, and 11.7 percent with other optimization enabled.